网格视图中的多选命令

时间:2019-03-21 10:25:23

标签: c# asp.net

<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"  CssClass="table-bordered table-hover table-responsive table" BackColor="White" BorderColor="White" CellPadding="3" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" >
    <AlternatingRowStyle BackColor="#CCCCCC" />
    <Columns>
        <asp:CommandField ShowSelectButton="True" ControlStyle-CssClass="accept" SelectText="Accept"  ControlStyle-ForeColor="Green" >
        <ControlStyle CssClass="accept" ForeColor="Green"></ControlStyle>
        </asp:CommandField>
        <asp:CommandField ShowSelectButton="True" ControlStyle-CssClass="reject" SelectText="Reject"  ControlStyle-ForeColor="Red" >
        <ControlStyle CssClass="reject" ForeColor="Red"></ControlStyle>
        </asp:CommandField>

        <asp:BoundField HeaderText="Status" />
        <asp:BoundField DataField="first_name" HeaderText="First name" SortExpression="first_name" />
        <asp:BoundField DataField="last_name" HeaderText="Last name" SortExpression="last_name" />
        <asp:BoundField DataField="c_email" HeaderText="Email" SortExpression="c_email" />
        <asp:BoundField DataField="contact" HeaderText="Contact" SortExpression="contact" />
        <asp:BoundField DataField="licenseno" HeaderText="License no" SortExpression="licenseno" />
        <asp:BoundField DataField="v_name" HeaderText="Vehicle name" SortExpression="v_name" />
        <asp:BoundField DataField="v_company" HeaderText="Company" SortExpression="v_company" />
        <asp:BoundField DataField="v_plate" HeaderText="Plate no" SortExpression="v_plate" />
        <asp:BoundField DataField="wheeler" HeaderText="Wheeler" SortExpression="wheeler" />
        <asp:BoundField DataField="damage_Details" HeaderText="Damage details" SortExpression="damage_Details" />
        <asp:BoundField DataField="street" HeaderText="Street" SortExpression="street" />
        <asp:BoundField DataField="landmark" HeaderText="Landmark" SortExpression="landmark" />
        <asp:BoundField DataField="pincode" HeaderText="Pincode" SortExpression="pincode" />

    </Columns>
    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="#752c82" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>

后面的代码:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridView1.SelectedRow.Cells[2].Text = "Accepted";
    string msg = "ACCEPTED";
    Session["c_email"] = GridView1.SelectedRow.Cells[5].Text;
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlConnection con = new SqlConnection(constr);
    con.Open();
    string insert = "insert into Status values(@email,@c_email,@status)";
    SqlCommand cmd = new SqlCommand(insert, con);

    cmd.Parameters.AddWithValue("@c_email", Session["c_email"].ToString());
    cmd.Parameters.AddWithValue("@email", Session["mechanic"].ToString());
    cmd.Parameters.AddWithValue("@status", msg.ToString());
    cmd.ExecuteNonQuery();
    Label1.Text = "You need to reach the customer within one hour and provide the needful service.";
    con.Close();
}

我有一个网格视图,其中包含带有2个选择按钮的两个命令字段。我希望页面上的按钮为“接受并拒绝”。但是我无法找到如何对其进行编码。

我已经为selectedIndexChanged的一个命令字段编码,但是如何为第二个命令字段编码。请帮帮我。

0 个答案:

没有答案