Link to home
Start Free TrialLog in
Avatar of dotnetpro

asked on

Textbox in Datagrid in VB.NET

How do i set the value of a textbox inside a Datagrid ?

I thought e.Item.FindControl("txttotals").text="hello" would do the job but nope..

Please help.
Avatar of atcis

Yes that should work in the ItemDataBound event.
Dim txtBox As TextBox = e.Item.FindControl("txttotals")
txtBox.Text = "hello"


Ctype(e.Item.FindControl("txttotals"), TextBox).Text = "hello"
Avatar of dotnetpro


I tried this

 Protected Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid2.ItemDataBound

            (CType(e.Item.FindControl("txttotals"), Textbox)).text = "hello"

        End Sub

 in ItemDatabound event and i am still getting the same Syntax error.
You have an extra set of parenthesys

CType(e.Item.FindControl("txttotals"), Textbox).text = "hello"
i am getting  object reference not set to instance of an object
Can you post the page source where showing the code for the ItemTemplate?
Here you go

<asp:Label ID="lblsalesext" runat="server"></asp:Label>
					<%#DataBinder.Eval(Container.DataItem, "Sales Ext")%>										
				    <FooterTemplate><asp:TextBox ID="txttotals" runat="server"></asp:TextBox></FooterTemplate>

Open in new window

Avatar of atcis

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When i do a quick watch on e.Item.FindControl("txttotals") I get "Nothing".
Cool it worked like a charm