c# - Specified argument was out of the range of valid values - RowDataBound -


i want change navigate url property in row data bound event. if coloumn not binded link want add navigate url= #

<asp:templatefield headertext="reportd link"  itemstyle-horizontalalign="center" >                     <itemtemplate>                    <asp:hyperlink id="lbl_rptlnk1" runat="server" navigateurl='<%#eval("reportlinks")%>'                             text='reported link' target="_blank" tooltip='<%#eval("reportlinks")%>'></asp:hyperlink>                   </itemtemplate>                     <itemstyle horizontalalign="left" />                 </asp:templatefield> 

aspx.cs code

  if (e.row.rowtype == datacontrolrowtype.datarow)     {         hyperlink mylink = (hyperlink)e.row.cells[4].controls[0];//slno,linkname,linkid,link          if (mylink.navigateurl == "waiting approval")         {             mylink.navigateurl = "#";         }      } 

getting error saying- specified argument out of range of valid values. parameter name: index

in rowdatabound event since control asp server control inside templatefield, can use findcontrol method on row find control:-

hyperlink lbl_rptlnk1 = (hyperlink)e.row.findcontrol("lbl_rptlnk1"); if (lbl_rptlnk1.navigateurl.trim() == "waiting approval") {      lbl_rptlnk1.navigateurl = "#"; } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -