前台
<td colspan="2">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="6"
onitemcommand="DataList1_ItemCommand">
<ItemTemplate>
<table class="Tb_Dl_Item">
<tr>
<td align="center">
<img class="Img" border="0" src='../../uploadfile/product/<%# Eval("cInvPicUrl") %>'
width="80px" height="80px" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="PicColorName" runat="server" Text='<%# Eval("cColorname") %>'></asp:Label>
</td>
</tr>
<tr>
<td align="center">
<asp:Label ID="LInvWCode" runat="server" Visible="false" Text='<%# Eval("cInvWCode") %>'></asp:Label>
<asp:DropDownList ID="ColorDropList" runat="server"></asp:DropDownList>
<asp:LinkButton ID="UpdateColor" runat="server" Text="修改" OnCommand="PicUpdate" CommandName="UpdatePic" CommandArgument='<%# Eval("cinvpiccode") %>'></asp:LinkButton>
</td>
</tr>
<tr>
<td align="center">
<asp:LinkButton ID="DelPic" runat="server" Text="删除" OnCommand="PicDel" OnClientClick="return Del();" CommandArgument='<%# Eval("cinvpiccode")%>'></asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
后台
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "UpdatePic")
{
int index = (int)e.Item.ItemIndex;
DropDownList ddl = (DropDownList)DataList1.Items[index].FindControl("ColorDropList");
string colorcode = ddl.SelectedValue.ToString();
Response.Write("colorcode");
string m_Sql = "update tb_inventoryPic set cColorCode ='" + colorcode + "' where cinvpicCode='" + WCodeUpdate.Text + "' ";
Dal m_Dal = new Dal();
bool m_Ret = m_Dal.ExecuteSql(m_Sql);
if (m_Ret)
{
Common.AlertMessage("修改成功!", "WebProductPic.aspx?invwcode=" + titletxt.Text + "");
}
else
{
Common.AlertMessage("修改失败!", "WebProductPic.aspx?invwcode=" + titletxt.Text + "");
}
}
}
ps:最近非常忙,从此以后会多写点自己的心得的.....
ps: 相关资料点滴
CommandArgument= <%# "参数1&"+"参数2&"+DataBinder.Eval(Container.DataItem,"id","{0}") % >
string tempId = e.CommandArgument.ToString();
开发网站过程中遇到LinkButton需要传两个参数的问题,经查互联网,现已成功:
<asp:LinkButton ID="lbEdit" runat="server" Text="通过审核" CommandArgument='<%# Eval("UserName")+","+Eval("yhlx")%>'
OnCommand="LinkButtonClick" ForeColor="blue"></asp:LinkButton>
CS:
protected void LinkButtonClick(object sender, CommandEventArgs e)
{
string[] ab = e.CommandArgument.ToString().Split(',');
string UserName=ab[0];
string yhlx=ab[1];
这样就可以取出值了。
DropDown1.Items.FindByValue(value).Selected=true
我在GridView中会弄`但到DataList中就不会
在GridView中的 ID 也是 int 的`
下面是我在GridView中的部分代码:
GridViewRow row = ProductGird .SelectedRow ;
int ID = (int)ProductGird.SelectedDataKey.Value;
string Name = row.Cells[1].Text;
但不知道到了Datalist 中要怎么调用?GridView运行正常
通常是这样:
1.把<%# Eval("Name")%>换成Label控件:
<asp:Label id="lab" ... Text='<%# Eval("Name")%>'></asp:Label>
2.把"购买"按钮的CommandName属性设一个值,如:
<asp:Button ... CommandName="buy"></asp:Button>
3.为"购买"按钮添加事件,即在DataList的ItemCommand事件中添加:
if(e.CommandName == "buy")
{
//此处仅示例如何获取绑定值
Label lab = (Label)e.Item.FindControl("lab");
if(lab != null)
Response.Write(lab.Text);
}