c# - Approve / reject through dropdownlist -


previously tried approve / reject through button , try code it..

this code when add buttons of approve / reject

    protected void grdfileapprove_rowcommand(object sender, gridviewcommandeventargs e)     {         if (e.commandname == "_approve")         {             //using (sqlconnection con = dataaccess.getconnected())             using (sqlconnection con = new          sqlconnection(configurationmanager.connectionstrings            ["mydms"].connectionstring))             {                 try                 {                     con.open();                     int rowindex = convert.toint32(e.commandargument);                     gridviewrow row = (gridviewrow)                    ((control)e.commandsource).namingcontainer;                     button prove_button = (button)row.findcontrol("btnapprove");                     sqlcommand cmd = new sqlcommand("approveee", con);                      //cmd.commandtype = commandtype.storedprocedure;                     cmd.commandtype = commandtype.storedprocedure;                     //con.execute("approve", new { userid, docid, approveid });                     cmd.parameters.add(new sqlparameter("@userid", userid));                     cmd.parameters.add(new sqlparameter("@docid", docid));                     cmd.parameters.add(new sqlparameter("@approveid", approveid));                      int result = cmd.executenonquery();                      if (result != 0)                     {                         grdfileapprove.databind();                     }                 }                 catch                 {                     apfi.text = "not approve";                 }                                 {                     con.close();                 }             }         }         else if (e.commandname == "_reject")         {             using (sqlconnection con = new              sqlconnection(configurationmanager.connectionstrings       ["mydms"].connectionstring))             {                 try                 {                     con.open();                     int rowindex = convert.toint32(e.commandargument);                     gridviewrow row = (gridviewrow)                ((control)e.commandsource).namingcontainer;                     linkbutton prove_button = (linkbutton)row.findcontrol("button1");                     sqlcommand cmd = new sqlcommand("sprejectapprove", con);                      cmd.commandtype = commandtype.storedprocedure;                     cmd.parameters.add(new sqlparameter("@userid",userid));                     cmd.parameters.add(new sqlparameter("@docid", docid));                     cmd.parameters.add(new sqlparameter("@approveid", approveid));                      int result = cmd.executenonquery();                      if (result != 0)                     {                         grdfileapprove.databind();                     }                 }                 catch                  {                     apfi.text = "rejct";                 }                                 {                     con.close();                 }             }         }     } 

and grdiview when add dropdown..

    <asp:gridview id="grdfileapprove" runat="server" backcolor="white"                    bordercolor="#336666" borderstyle="double" borderwidth="3px" cellpadding="4"                    gridlines="horizontal" autogeneratecolumns="false"                      onrowcommand="grdfileapprove_rowcommand" onrowdatabound="onrowdatabound" >                      <columns>                        <asp:templatefield headertext="s no">                            <itemtemplate>                                <%# container.dataitemindex+1 %>                                <asp:hiddenfield runat="server" id="hdnfileid" value='<%# eval("docid") %>' />                            </itemtemplate>                        </asp:templatefield>                        <asp:boundfield datafield="docid" headertext="documentid"  />                        <asp:boundfield datafield="docname" headertext="docname"  />                        <asp:boundfield datafield="uploadfile" headertext="file name" />                        <asp:boundfield datafield="doctype" headertext="document" />                        <asp:boundfield datafield="deptype" headertext="department" />  <%--                       <asp:boundfield headertext="approveid" datafield="approveid" ></asp:boundfield> --%>                <asp:templatefield>                     <itemtemplate>                        <asp:label id="lblcountry" runat="server" text='<%# eval("approveid") %>' visible = "false" />                          <asp:dropdownlist id="dropdownlist4" runat="server" class="vpb_dropdown">                         </asp:dropdownlist>                     </itemtemplate>                 </asp:templatefield>                      </columns>                 <rowstyle backcolor="white" forecolor="#333333" />                 <footerstyle backcolor="white" forecolor="#333333" />                 <pagerstyle backcolor="#336666" forecolor="white" horizontalalign="center" />                 <selectedrowstyle backcolor="#339966" font-bold="true" forecolor="white" />                 <headerstyle backcolor="#336666" font-bold="true" forecolor="white" />             </asp:gridview> 

now want code of dropdown.. when click on approve/reject can approve/reject how code , how approve or reject through dropdown..

i have changed markup dropdownlist4:

<asp:dropdownlist id="dropdownlist4" runat="server" class="vpb_dropdown" autopostback="true" onselectedindexchanged="dropdownlist4_selectedindexchanged">     <asp:listitem text="approve" value="approve"></asp:listitem>     <asp:listitem text="reject" value="reject"></asp:listitem> </asp:dropdownlist> 

and in code:

protected void dropdownlist4_selectedindexchanged(object sender, eventargs e) {     dropdownlist ddl = sender dropdownlist;     if (ddl.selectedvalue == "approved")     {         //code approve     }     else if (ddl.selectedvalue == "reject")     {         //code reject     } } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -