drop down menu - Loosing Attributes in DropDownList asp.net -


i set attributes dropdownlist

the problem when try read them in button click null !!

i not sure of postback or not see code below

why , how fix it?

this code

    protected void ddlreps_databound(object sender, eventargs e)     {         foreach (system.data.datarow row in dt.rows)         {             ddlreps.items.findbyvalue(row["reportid"].tostring()).attributes.add("reportpath", row["reportpath"].tostring());             ddlreps.items.findbyvalue(row["reportid"].tostring()).attributes.add("reportserver", row["reportserver"].tostring());         }         string attribvalue1 = ddlreps.selecteditem.attributes["reportpath"];      //when check here can see valu     }      protected void btnviewreport_click(object sender, eventargs e)     {         string attribvalue2 = ddlreps.selecteditem.attributes["reportpath"];      //here null :(     } 

also here page load code

   protected void page_load(object sender, eventargs e)     {         if (!user.identity.isauthenticated) // if user logged in         {             response.redirect("~/accessdenied.aspx");         }           if (!page.ispostback)         {             if (session["username"] != null)              {                 lblwelcome.text = "welcome " + session["username"].tostring();             }             string connstr = configurationmanager.connectionstrings["main"].connectionstring;             sqlconnection conn = new sqlconnection(connstr);             try             {                 conn.open();                  sqlcommand cmd = new sqlcommand("mysp", conn);                 sqldataadapter da = new sqldataadapter(cmd);                 cmd.commandtype = commandtype.storedprocedure;                    da.fill(dt);                 if (dt.rows.count > 0)                 {                     //populate dropdownlist                     ddlreps.datasource = dt;                     ddlreps.datatextfield = "reportname";                     ddlreps.datavaluefield = "reportid";                     ddlreps.databind();                 }             }             catch (system.data.sqlclient.sqlexception ex)             {                 string msg = "fetch error:";                 msg += ex.message;                 throw new exception(msg);             }                         {                 conn.close();             } } 

and here markeup ddl asp:scriptmanager used because using reportviewer

<div>         <form id="form2" runat="server">             <asp:scriptmanager id="scriptmanager1" runat="server"></asp:scriptmanager>              <div class="report-module">                 <h2>choose report</h2>                              <asp:dropdownlist id="ddlreps" runat="server" ondatabound="ddlreps_databound" cssclass="ddl" viewstatemode="enabled"></asp:dropdownlist>                </div>             <rsweb:reportviewer id="reportviewer" runat="server" width="100%" processingmode="remote" font-names="sans-serif" font-size="8pt" waitmessagefont-names="verdana" waitmessagefont-size="14pt" height="457px" backcolor="white" visible="false" splitterbackcolor="51, 181, 229">             </rsweb:reportviewer>         </form>     </div> 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -