本文介绍了如何使用FindControl从TextBox - GridView获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<asp:GridView ID="GridView1" runat="server" CellPadding="1" CellSpacing="1" DataKeyNames="PostID"
AutoGenerateColumns="False" Width="98%" OnRowCommand="GridView1_RowCommand"
AllowPaging="True" ShowHeader="false" onrowdatabound="GridView1_RowDataBound" BackColor="White" RepeatLayout="Table" BorderColor="#B0E3FF" BorderStyle="None" BorderWidth="1px" style="margin-left: 9px; height:auto">
<asp:Button ID="btnComnt" runat="server" OnClick="btnComnt_Click" class="btnComment" Text="Comment" />
<asp:HiddenField ID="HiddenField1" Value='<%#Eval("PostID") %>' runat="server" />
</asp:GridView>
我将数据输入HiddenField。
I do get the data into the HiddenField .
protected void btnComnt_Click(object sender, EventArgs e)
{
int userid = int.Parse(Session["UnAuthentication"].ToString());
string date = DateTime.Now.ToString();
int privates = 0;
TextBox txtNewComent = FindControl("txtComent") as TextBox;
HiddenField postNo = FindControl("HiddenField1") as HiddenField;
Post post = new Post();
post.Comment = new Comments(int.Parse(postNo.Value), txtNewComent.Text, userid);
dll.PostReply(post);
}
我想在添加TextBox和HiddenField时添加值帖子。
请帮我把代码从GridView上的HiddenField中取值到postNo。
我可以将值填充到HiddenField但是我无法从
I want to add the values from TextBox and HiddenField when i am adding the Post.
Please help me with the code to take the values from the HiddenField on GridView to postNo.
I can populate value to HiddenField but i cannot read it back from code behind
推荐答案
foreach (GridViewRow row in GridView1.Rows)
{
string textBoxText = ((TextBox)row.FindControl("txtComent")).Text;
string userId = ((HiddenField)row.FindControl("HiddenField1")).Value;
Post post = new Post();
post.Comment = new Comments(int.Parse(userId), textBoxText.ToString(), userid);
dll.PostReply(post);
this.PopulateData();
}
这篇关于如何使用FindControl从TextBox - GridView获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!