Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

c# - Approve / reject through dropdownlist

Previously I tried to approve / reject through button and try to code it..

This is code when I 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";
                }
                finally
                {
                    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";
                }
                finally
                {
                    con.Close();
                }
            }
        }
    }

and this grdiview when I 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 I want to code of dropdown.. when I click on approve/reject it can be approve/reject how to code it and how to approve or reject through dropdown..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have changed markup for 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 the code:

protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddl = sender as DropDownList;
    if (ddl.SelectedValue == "Approved")
    {
        //Code to approve
    }
    else if (ddl.SelectedValue == "Reject")
    {
        //Code to reject
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...