Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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;

.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);
}
I am getting null value for Textbox txt.

Thanks in Advance
Posted
Updated 12-May-11 23:54pm
v3
Comments
Ankur\m/ 13-May-11 6:13am    
TextBox txt = (TextBox)e.Row.Cells[1].FindControl("txt");
txtS.ID = "txt" + e.Row.RowIndex;

txtS.ID - Typo?

1 solution

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..

C++
<asp:LinkButton ID="LB" CommandName="saveAnswer" CommandArgument='<%#Eval("Column name of your textbox") %>' runat="server">Save</asp:LinkButton>


in cs file..


C#
if (e.CommandName == "saveAnswer")
{
string strTextboxValue = e.CommandArgument.ToString();
//your textbox value

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900