c# - FindControl doesn't find control -


i setting gridview can select several events , add eventid's comma delimited string. going subscription service, need know events user wants subscribed to.

i used template field add checkbox use indicator of event items wanted.

so gridview looks this

<asp:gridview id="gridview1"      runat="server"      allowpaging="true"      allowsorting="true"      autogeneratecolumns="false"      datasourceid="sqldatasource1"      pagesize="15"      viewstatemode="enabled" selectedrowstyle-backcolor="purple">     <columns>         <asp:templatefield>             <itemtemplate>                 <asp:checkbox id="eventselected" runat="server" />             </itemtemplate>         </asp:templatefield>         <asp:boundfield datafield="eventid" headertext="eventid" insertvisible="false" readonly="true" sortexpression="eventid" />         <asp:boundfield datafield="eventname" headertext="eventname" sortexpression="eventname" />         <asp:boundfield datafield="basetypekey" headertext="basetypekey" sortexpression="basetypekey" />         <asp:boundfield datafield="basetypedesc" headertext="basetypedesc" readonly="true" sortexpression="basetypedesc" />      </columns> </asp:gridview> 

and information populating quite nicely.

my code retrieve selected items should simple isn't functioning yet.

private string getcheckedevents() {     list<string> outputstring = new list<string>();     foreach (gridviewrow row in gridview1.rows)     {         checkbox cb = (checkbox)row.findcontrol("eventselected");         if (cb != null && cb.checked)         {             outputstring.add(row.findcontrol("eventid").tostring());         }     }     return string.join(",", outputstring); } 

when debugging code though, checkbox set correctly , enters if statement hits single line of code , comes

an exception of type 'system.nullreferenceexception' occurred in eventemailerconfiguration.dll not handled in user code

trying navigate inside object explorer given debugger pita least.

am not traversing right location?

how extract information need?

you cannot find boundfield since it's not real control. have use row.cells[index].text:

outputstring.add(row.cells[1].text); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -