vb.net - Object not set to an instance in asp.net -


i have code:

dim txt = ctype(gridview1.findcontrol("cnt_content"), textbox)         txt.attributes.add("style", "word-wrap:break-word;") 

i'm getting txt object not set instance of object that's 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?

my guess trying find control in rowdatabound event, this:

sub gridview1_rowdatabound(byval sender object, byval e gridviewroweventargs)  end sub 

you need check control on data rows, not header or footer rows, control not exist in other types of rows, try this:

sub gridview1_rowdatabound(byval sender object, byval e gridviewroweventargs)     ' check in data rows, ignore header , footer rows     if e.row.rowtype = datacontrolrowtype.datarow         ' determine if in edit mode or not         if gridview1.editindex = -1             ' not in edit mode label control defined in itemtemplate of grid view             ' put logic here label control         else             ' in edit mode textbox control defined in edititemtemplate of grid view             dim txt = ctype(gridview1.findcontrol("cnt_content"), textbox)             txt.attributes.add("style", "word-wrap:break-word;")         end if     end if end sub 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -