i have this code:
Dim txt = CType(GridView1.FindControl("cnt_content"), TextBox)
txt.Attributes.Add("style", "word-wrap:break-word;")
i'm always getting that txt is an object not set to an instance of an object that's my asp code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
DataKeyNames="cnt_id">
<Columns>
<asp:TemplateField HeaderText="Content">
<EditItemTemplate>
<asp:TextBox ID="cnt_content" runat="server" Text='<%# Bind("cnt_content") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblcnt_content" runat="server" Text='<%# Bind("cnt_content") %>'></asp:Label>
</ItemTemplate>
<ItemStyle wrap="true" Width="400px" />
</asp:TemplateField>
any help?
cnt_contentdoes not exist or isn't aTextBox...GridView1.FindControl("cnt_content")to a local variable and examine it in the debugger - my guess is it will be returningnull.Dim txt = ...code running at? Also, you have 2 controls with the same name. Although allowed in this context that is usually a very bad idea.cnt_content. I realize they are in different templates and should never exist at the same time, but it is confusing for anyone else looking at your code.