c# - Handling nulls in RadioButtonList in Repeater control -


we have following radiobuttonlist in our repeater control:

<asp:radiobuttonlist id="rdlmhorseptype" text='<%#string.isnullorempty((string)eval("rdlmhorseptype")) ? "electric start" : eval("rdlmhorseptype") %>' runat="server" validationgroup ="stype" repeatdirection="horizontal" textalign="right" style="display:inline;"  autopostback="true" onselectedindexchanged="rblpurchasetype_selectedindexchanged">    <asp:listitem text="electric start" />    <asp:listitem text="recoil" /> </asp:radiobuttonlist><br /> 

our normal business process requires user enter account number check existence of records associated account number.

if records exist, repeater control form populated records.

users can make whatever modifications wish make.

this part works great.

if no record exists, user required enter his/her information , submit database.

this having problem.

this issue because if no values rdlmhorseptype exists on database, following error raised:

'rdlmhorseptype ' has selectedvalue invalid because not exist in list of items. parameter name: value

since there 2 values in rdlmhorseptype radiobuttonlist control, used electric start default value eliminate error.

problem electric start gets inserted database , displayed selected value.

i attempted use 0 in:

text='<%#string.isnullorempty((string)eval("rdlmhorseptype")) ? "0" : eval("rdlmhorseptype") %>'  

but throws same error.

any ideas how fix error allows display of correct selected value database?

that error way, points database table used initializing datatable values:

        dr = dt.newrow();         dr["rownumber"] = 1;         dr["rdlmhorseptype"] = string.empty;         dr["rblissues"] = string.empty;         dr["vesseltypeuse"] = string.empty;         dt.rows.add(dr);     }     else     {         dt = (datatable)viewstate["currenttable"];     }     //store datatable in viewstate future reference     viewstate["currenttable"] = dt;     if (dt.rows.count > 0)     {         //bind repeater datatable         repeater2.datasource = dt;         repeater2.databind();     } } 

add value attribute list item below code

 <asp:radiobuttonlist id="rdlmhorseptype" text='<%#string.isnullorempty((string)eval("rdlmhorseptype")) ? "electric start" : eval("rdlmhorseptype") %>' runat="server" validationgroup ="stype" repeatdirection="horizontal" textalign="right" style="display:inline;"  autopostback="true" onselectedindexchanged="rblpurchasetype_selectedindexchanged">        <asp:listitem value="0" text="electric start" />        <asp:listitem value="1" text="recoil" />     </asp:radiobuttonlist><br /> 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -