asp:TextBox在DataList中时,怎么或取它的值?
<asp:DataListID="DataList1"runat="server"DataKeyField="id"DataSourceID="SqlDataSource...
<asp:DataList ID="DataList1" runat="server" DataKeyField="id" DataSourceID="SqlDataSource1" Width="584px" CaptionAlign="Left">
<ItemTemplate>
<img src='<%# Eval("pictureURL") %>' style="width: 70px; height: 70px" />
价格:
<asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>'></asp:Label>
名称:
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>'></asp:Label>
数量:
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("quantity") %>' <OnTextChanged="TextBox1_TextChanged" Width="29px" AutoPostBack="True"></asp:TextBox> //.....一个文本框,他的内容改变时会触发protected void TextBox1_TextChanged(object sender, EventArgs e)事件,我怎么获得文本框中的值.注意虽然有id,但它在DataList有多个出现.
总价:
<asp:Label ID="categoryPriceLabel" runat="server" Text='<%# Eval("categoryPrice") %>'>
</asp:Label>
</ItemTemplate>
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:a1230192748ConnectionString %>"
SelectCommand="SELECT * FROM [goodBought] WHERE ([id] = @id)">
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</div>
<div align="center">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource2" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="a" HeaderText="合计" ReadOnly="True"
SortExpression="categoryPrice" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:a1230192748ConnectionString %>"
SelectCommand="SELECT sum([categoryPrice]) as a FROM [goodBought] WHERE ([id] = @id)">
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource> 展开
<ItemTemplate>
<img src='<%# Eval("pictureURL") %>' style="width: 70px; height: 70px" />
价格:
<asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>'></asp:Label>
名称:
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>'></asp:Label>
数量:
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("quantity") %>' <OnTextChanged="TextBox1_TextChanged" Width="29px" AutoPostBack="True"></asp:TextBox> //.....一个文本框,他的内容改变时会触发protected void TextBox1_TextChanged(object sender, EventArgs e)事件,我怎么获得文本框中的值.注意虽然有id,但它在DataList有多个出现.
总价:
<asp:Label ID="categoryPriceLabel" runat="server" Text='<%# Eval("categoryPrice") %>'>
</asp:Label>
</ItemTemplate>
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:a1230192748ConnectionString %>"
SelectCommand="SELECT * FROM [goodBought] WHERE ([id] = @id)">
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</div>
<div align="center">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource2" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="a" HeaderText="合计" ReadOnly="True"
SortExpression="categoryPrice" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:a1230192748ConnectionString %>"
SelectCommand="SELECT sum([categoryPrice]) as a FROM [goodBought] WHERE ([id] = @id)">
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource> 展开
3个回答
展开全部
string tt="";
for(int i = 0; i < this.DataList1.Items.Count; i++)
{
TextBox T = ((System.Web.UI.WebControls.TextBox)DataList1.Items[i].FindControl("TextBox1"));//TextBox1为控件id,id是唯一的
tt=T.Text;//获取值
}
如果想获取其他控件的值,可直接替换
TextBox T = ((System.Web.UI.WebControls.TextBox)DataList1.Items[i].FindControl("TextBox2"));
Label l = ((System.Web.UI.WebControls.Label)DataList1.Items[i].FindControl("Label1"));
for(int i = 0; i < this.DataList1.Items.Count; i++)
{
TextBox T = ((System.Web.UI.WebControls.TextBox)DataList1.Items[i].FindControl("TextBox1"));//TextBox1为控件id,id是唯一的
tt=T.Text;//获取值
}
如果想获取其他控件的值,可直接替换
TextBox T = ((System.Web.UI.WebControls.TextBox)DataList1.Items[i].FindControl("TextBox2"));
Label l = ((System.Web.UI.WebControls.Label)DataList1.Items[i].FindControl("Label1"));
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个你要在DataList控件中先找到TextBox控件,然后给他赋值,给你2个语句,自己去看看,我这里用的是没问题的 TextBox TextBox1 = (TextBox)DataList1.Items[DataList1.EditItemIndex].FindControl("TextBox1");是找到控件,你好好看看吧!!!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
(e.items.findcontrol("") as TextBox).Text
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询