c# - ASP.NET Passing asp:Repeater value to asp:Button CssClass attribute -


i have payment method repeater contains button. have new button styles need applied. new button style changes based on btnmode setting in database set string representing css class selector. css works fine.

i put in aspx page:

<asp:button id="btnedit"              runat="server"              clientidmode="static"              cssclass='<%# eval("btnmode") %>'              text="edit"              commandname="changepaymentprofile"              commandargument='<%# eval("paymentsourceid") + "|" + eval("authnetpaymentprofileid")%>' />   

in aspx.cs

    //command button clicked: change payment method     else if (e.commandname.tolower().equals("changepaymentprofile"))     {         hdchangeyn.value = "y";          showaddpaymentform();          //display billing address of selected card         hsparams.add("customerid", user.identity.name);         hsparams.add("paymentsourceid", strpaymentsourceid);         datatable dt = dbhelper.getdatatablesp("234_accountaddress__bypaysourceid", hsparams);          if (dt.rows.count > 0)         {             tbfistname.text = dt.rows[0]["firstname"].toobjectstring();             tblastname.text = dt.rows[0]["lastname"].toobjectstring();             inputaddress1.text = dt.rows[0]["address"].toobjectstring();             inputaddress2.text = "";              string strcountrycd = dt.rows[0]["countrycd"].toobjectstring();             ddlcountry_update(strcountrycd); //update country & state ddl because country can foreign country              ddlcountry.selectedvalue = strcountrycd;             inputcity.text = dt.rows[0]["city"].toobjectstring();             ddlstate.selectedvalue = dt.rows[0]["stateprovinceid"].toobjectstring();             inputzipcode.text = dt.rows[0]["zipcode"].toobjectstring();              ddlcardtype.selectedvalue = dt.rows[0]["cardtype"].toobjectstring();         }     } 

when load page in browser <%# eval("btnmode") %> not resolved value. see when open inspector:

<input      id="btnedit"      class="<%# eval("btnmode") %>"     type="submit"      name="ctl00$ctl00$contentplaceholderfront$contentplaceholderfront$rptlist$ctl01$btnprimary"      value=""      onclick="javascript:webform_dopostbackwithoptions(new webform_postbackoptions(&quot;ctl00$ctl00$contentplaceholderfront$contentplaceholderfront$rptlist$ctl01$btnprimary&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" > 

it important point out attribute commandargument='<%# eval("paymentsourceid") %>' work, , btnmode contain valid data.

as wrote in comment, not properties in asp.net controls can databound. cssclass 1 cannot databound.

to around this, can add onitemdatabound event handler repeater button is. in event handler can user e.item.dataitem value want , set cssclass on button. sample code:

<asp:repeater id="repeatertest" runat="server" onitemdatabound="repeatertest_itemdatabound">     <itemtemplate>         <div>             <asp:button id="testbutton" runat="server" text='<%# eval("sometext") %>'/>         </div>     </itemtemplate> </asp:repeater> 

and code behind:

protected void page_load(object sender, eventargs e) {     var testdata = enumerable.range(1, 10).select(i => new { sometext = "button " + i.tostring() }).tolist();     repeatertest.datasource = testdata;     repeatertest.databind(); } protected void repeatertest_itemdatabound(object sender, repeateritemeventargs e) {     dynamic foo = e.item.dataitem;     ((button)e.item.findcontrol("testbutton")).cssclass = foo.sometext; } 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -