Jump to content

Finding a control


Bhushan
 Share

Recommended Posts

Hi,I have a TextBox inside a HTML table which is inside a DataGrid.I used TextBox t=(TextBox)DetailsGrid.FindControl("txtName");Response.Write(t.Text);But its not working. Please let me know.

Link to comment
Share on other sites

Hi,When I add (.) it gave me error saying TextBox defines a class where a variable is expected. In the first place, do I have to include anything else??.I have hierarchy like this.I am facing a problem in my project where in I have made use of a Data Grid and inside it I have used a HTML table and inside <td> I am using a asp TextBox.When I tried to find out this TextBox using string str=((TextBox)e.Item.Cells[0].FindControl("txtName")).Text;Response.Write(str);It is giving me an error saying “bject reference not set to an instance of an Object”Please suggest me how can I resolve this??. I am also mailing you the piece of code which might be useful for you to pin point my mistake !. I tried here something different. But even this didn't work out. ASPX code: I have the following textbox under <table> which is inside a DataGrid. <td><asp:TextBox ID="txtName" Runat="server" ReadOnly=True Text='<%#DataBinder.Eval(Container.DataItem,"ResourceName")%>'></asp:TextBox></td> <FooterTemplate><asp:Button ID="btnEdit" Runat="server" Text="EDIT" CommandName="edit_here" /></FooterTemplate> I have a ItemCommand=”mCommandHandler” as my DataGrid property. CodeBehind: public void mCommandHandler(object sender,DataGridCommandEventArgs e) { if(e.CommandName=="edit_here") { TextBox t=(TextBox)e.Item.FindControl("txtName"); string str=t.Text; Response.Write(str); } } Please help me in getting rid of this problem.Thanks in advance,Bhushan

Link to comment
Share on other sites

Hi ,I am catching the ItemCommand event as below and trying to find a control.public void mCommandHandler(object sender,DataGridCommandEventArgs e) { if(e.CommandName=="edit_here") { TextBox t=(TextBox)Page.FindControl("txtName"); labl.Text=t.Text; } }It's throwing me the same error saying "Object reference is not set to an instance of an Object".Do you have any Idea ??.HTML code is as follows :<asp:datagrid id="DetailsGrid" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 160px" runat="server" HeaderStyle-ForeColor="blue" HeaderStyle-Font-Bold="True" OnItemCommand="mCommandHandler" AutoGenerateColumns="False" EditItemStyle-BackColor="#cccfff" BackColor="Transparent" BorderColor="Transparent" OnCancelCommand="cancel" OnEditCommand="edithere" ShowFooter="True"> <EditItemStyle BackColor="#CCCFFF"></EditItemStyle> <HeaderStyle Font-Bold="True" Wrap="False" ForeColor="White" BackColor="Navy"></HeaderStyle> <FooterStyle BackColor="White"></FooterStyle> <Columns> <asp:TemplateColumn HeaderText="Employee Details"> <ItemTemplate> <table> <tr> <td> Name </td> <td> <asp:TextBox ID="txtName" Runat="server" ReadOnly="True" Text="Hello man"></asp:TextBox> </td> </tr> <tr> <td> NT ID </td> <td> <asp:TextBox ID="Textbox1" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SecureNTID")%>'> </asp:TextBox> </td> </tr> <tr> <td> Designation </td> <td> <asp:TextBox ID="Textbox2" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Designation")%>'> </asp:TextBox> </td> </tr> <tr> <td> Address </td> <td> <asp:TextBox ID="Textbox3" Runat="server" TextMode="MultiLine" Text='<%#DataBinder.Eval(Container.DataItem,"ResourceAddress")%>'> </asp:TextBox> </td> </tr> </table> </ItemTemplate> <FooterTemplate> <asp:Button ID="btnEdit" Runat="server" Text="EDIT" CommandName="edit_here" /> </FooterTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...