datalist获取值问题
<asp:DataListID="DataList1"runat="server"Width="100%"RepeatDirection="Vertical"OnData...
<asp:DataList ID="DataList1" runat="server" Width="100%"
RepeatDirection ="Vertical" OnDataBinding ="OnDataBinding" OnItemDataBound ="OnItemDataBound" OnDeleteCommand ="OnDeleteCommand" OnCancelCommand ="OnCancelCommand" >
<ItemTemplate>
<asp:TextBox runat ="server" ID ="name1" Text =' <%# Eval("content_name") %>'> </asp:TextBox>
<asp:TextBox runat ="server" ID ="name2" Text =' <%# Eval("content_sex") %>' > </asp:TextBox>
<asp:TextBox runat ="server" ID ="TextBox1" Text =' <%# Eval("content_id") %>' > </asp:TextBox>
<asp:TextBox runat ="server" ID ="TextBox2" Text =' <%# Eval("content_count") %>' > </asp:TextBox>
<asp:Button runat ="server" ID ="bt1" Text ="获取当前列的所有值" OnClick ="bt1click"> </asp:Button>
</ItemTemplate>
</asp:DataList>
如上
当点击bt1时,获取name1,name2,TextBox1的值怎么实现 展开
RepeatDirection ="Vertical" OnDataBinding ="OnDataBinding" OnItemDataBound ="OnItemDataBound" OnDeleteCommand ="OnDeleteCommand" OnCancelCommand ="OnCancelCommand" >
<ItemTemplate>
<asp:TextBox runat ="server" ID ="name1" Text =' <%# Eval("content_name") %>'> </asp:TextBox>
<asp:TextBox runat ="server" ID ="name2" Text =' <%# Eval("content_sex") %>' > </asp:TextBox>
<asp:TextBox runat ="server" ID ="TextBox1" Text =' <%# Eval("content_id") %>' > </asp:TextBox>
<asp:TextBox runat ="server" ID ="TextBox2" Text =' <%# Eval("content_count") %>' > </asp:TextBox>
<asp:Button runat ="server" ID ="bt1" Text ="获取当前列的所有值" OnClick ="bt1click"> </asp:Button>
</ItemTemplate>
</asp:DataList>
如上
当点击bt1时,获取name1,name2,TextBox1的值怎么实现 展开
展开全部
1,把bt1的CommandName属性随便设一个名字,如“Get”,
2,datalist添加事件ItemCommand。具体事件为:
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Get")
{
string str1= ((TextBox)e.Item.FindControl("TextBox1")).Text;
}
}
里面的str1就是取得文本框TextBox1的值,其他以此类推
2,datalist添加事件ItemCommand。具体事件为:
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Get")
{
string str1= ((TextBox)e.Item.FindControl("TextBox1")).Text;
}
}
里面的str1就是取得文本框TextBox1的值,其他以此类推
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询