Click here to Skip to main content
15,942,793 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have an ASP Grid where i set the ID of textbox dynamically in RowDataBound event
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.

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
Updated 12-May-11 23:54pm
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

in Source file do this..

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

in cs file..

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