在ASP网格中找不到文本框 [英] Unable to find textbox in ASP Grid
本文介绍了在ASP网格中找不到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP网格,其中在RowDataBound事件中动态设置了文本框的ID
代码
Hi,
I have an ASP Grid where i set the ID of textbox dynamically in RowDataBound event
Code
TextBox txt = (TextBox)e.Row.Cells[1].FindControl("txt");
txtS.ID = "txt" + e.Row.RowIndex;
.但是在RowCommand事件中,我找不到文本框.
代码
.But on RowCommand event i am unable to find the textbox.
Code
if (e.CommandName == "saveAnswer")
{
int RowIndex = Convert.ToInt32(e.CommandArgument.ToString());
TextBox txt = (TextBox)Grid.Rows[RowIndex].FindControl("txt" + RowIndex);
}
我为文本框txt获取空值.
在此先感谢
I am getting null value for Textbox txt.
Thanks in Advance
推荐答案
您在复杂环境中所做的工作..
在您的CommandName上,您可以分配文本框列的CommangArgument. 因此您将使用CommandArgument获取文本....like
在源文件中执行此操作..
Why ur doing in complex..
On your CommandName u can assign CommangArgument of your textbox column..
so u will get text with CommandArgument....like
in Source file do this..
<asp:LinkButton ID="LB" CommandName="saveAnswer" CommandArgument='<%#Eval("Column name of your textbox") %>' runat="server">Save</asp:LinkButton>
在cs文件中..
in cs file..
if (e.CommandName == "saveAnswer")
{
string strTextboxValue = e.CommandArgument.ToString();
//your textbox value
}
这篇关于在ASP网格中找不到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文