Gridview RowCommand 不起作用

发布于 2024-10-06 08:34:19 字数 3252 浏览 3 评论 0原文

我在尝试在网格视图中触发 rowcommand 事件时遇到问题。我按照 MSDNet 的代码示例进行操作,但我无法弄清楚为什么它不起作用。代码如下。谢谢。

<asp:GridView ID="GridViewProducts" runat="server" AutoGenerateColumns="False" 
    BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" 
    CellPadding="5" CellSpacing="1" DataKeyNames="Pkey" 
    DataSourceID="SqlDataSourceProducts" ForeColor="Black" GridLines="Vertical">
    <FooterStyle BackColor="#CCCCCC" />
    <PagerSettings PageButtonCount="20" />
    <Columns>
        <asp:BoundField DataField="Product" HeaderText="Product" >
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Left" />
        </asp:BoundField>
        <asp:TemplateField HeaderText="Interest">
            <ItemTemplate>
                <asp:DropDownList ID="ddlProductInterest" runat="server" SelectedValue='<%# Bind("ProductInterest") %>'>
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem>Low</asp:ListItem>
                    <asp:ListItem>Medium</asp:ListItem>
                    <asp:ListItem>High</asp:ListItem>
                    <asp:ListItem>None</asp:ListItem>
                </asp:DropDownList>
             </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="">
            <ItemTemplate>
                <asp:Button runat="server" ID="TestButton" Text="Button" CommandName="Test" 
                CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>" />
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="center" />
            <ItemStyle HorizontalAlign="center" />
       </asp:TemplateField>
    </Columns>
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
    <AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>

++Code Behind +++

Sub GridViewProducts_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

   If e.CommandName = "Test" Then

    Dim index = Convert.ToInt32(e.CommandArgument)
    Dim row = GridViewProducts.Rows(index)
    Dim MyString As String = row.Cells(0).Text

    strSQL = "INSERT INTO tblClosedProducts (" & _
         "Product, ClosedBy, DateClosed " & _
         ") VALUES (" & _
         "@Product, @ClosedBy, @DateClosed " & _
         ")"

    Dim MyParameters1 As SqlParameter() = { _
       New SqlParameter("@Product", SqlDbType.VarChar), _
       New SqlParameter("@ClosedBy", SqlDbType.VarChar), _
       New SqlParameter("@DateClosed", SqlDbType.SmallDateTime) _
    }

    MyParameters1(0).Value = row.Cells(0).Text
    MyParameters1(1).Value = GetInfo.GetFullName(UCase(Right(HttpContext.Current.User.Identity.Name.ToString(), 4)))
    MyParameters1(2).Value = DateAdd("h", -1, Now())

    objData.SQLExecuteNonQuery(strSQL, CommandType.Text, MyParameters1)

  End If

End Sub

I am having problems trying to get a rowcommand event to fire in a gridview. I followed the code example from MSDNet but I cannot figure out why it is not working. The code is below. Thank you.

<asp:GridView ID="GridViewProducts" runat="server" AutoGenerateColumns="False" 
    BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" 
    CellPadding="5" CellSpacing="1" DataKeyNames="Pkey" 
    DataSourceID="SqlDataSourceProducts" ForeColor="Black" GridLines="Vertical">
    <FooterStyle BackColor="#CCCCCC" />
    <PagerSettings PageButtonCount="20" />
    <Columns>
        <asp:BoundField DataField="Product" HeaderText="Product" >
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Left" />
        </asp:BoundField>
        <asp:TemplateField HeaderText="Interest">
            <ItemTemplate>
                <asp:DropDownList ID="ddlProductInterest" runat="server" SelectedValue='<%# Bind("ProductInterest") %>'>
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem>Low</asp:ListItem>
                    <asp:ListItem>Medium</asp:ListItem>
                    <asp:ListItem>High</asp:ListItem>
                    <asp:ListItem>None</asp:ListItem>
                </asp:DropDownList>
             </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="">
            <ItemTemplate>
                <asp:Button runat="server" ID="TestButton" Text="Button" CommandName="Test" 
                CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>" />
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="center" />
            <ItemStyle HorizontalAlign="center" />
       </asp:TemplateField>
    </Columns>
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
    <AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>

++Code Behind +++

Sub GridViewProducts_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

   If e.CommandName = "Test" Then

    Dim index = Convert.ToInt32(e.CommandArgument)
    Dim row = GridViewProducts.Rows(index)
    Dim MyString As String = row.Cells(0).Text

    strSQL = "INSERT INTO tblClosedProducts (" & _
         "Product, ClosedBy, DateClosed " & _
         ") VALUES (" & _
         "@Product, @ClosedBy, @DateClosed " & _
         ")"

    Dim MyParameters1 As SqlParameter() = { _
       New SqlParameter("@Product", SqlDbType.VarChar), _
       New SqlParameter("@ClosedBy", SqlDbType.VarChar), _
       New SqlParameter("@DateClosed", SqlDbType.SmallDateTime) _
    }

    MyParameters1(0).Value = row.Cells(0).Text
    MyParameters1(1).Value = GetInfo.GetFullName(UCase(Right(HttpContext.Current.User.Identity.Name.ToString(), 4)))
    MyParameters1(2).Value = DateAdd("h", -1, Now())

    objData.SQLExecuteNonQuery(strSQL, CommandType.Text, MyParameters1)

  End If

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风尘浪孓 2024-10-13 08:34:20

@rtpHarry 是正确的,这是连接事件的有效方法。连接事件的另一种方法是更改​​后面代码中方法的签名,以将 Handles Me.GridViewProducts.RowCommand 添加到末尾:

Sub GridViewProducts_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles Me.GridViewProducts.RowCommand

@rtpHarry is correct, and that is a valid way to wire up the event. Another method of wiring the event would be to change the signature of your method in the code behind to add Handles Me.GridViewProducts.RowCommand to the end:

Sub GridViewProducts_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles Me.GridViewProducts.RowCommand
南巷近海 2024-10-13 08:34:20
protected void Add_Update_Remove_Row(int Index, string Operation)
{
    //DataTable dt = (DataTable)ViewState["Table_BinaryPayment"];

    int ID = Index;

    Label lblddt = (Label)GridView1.Rows[Index].FindControl("Label2");
    Label lblttm = (Label)GridView1.Rows[Index].FindControl("Label1");
    Label lblid = (Label)GridView1.Rows[Index].FindControl("lblID");
    Label lblaeamt = (Label)GridView1.Rows[Index].FindControl("lblamt");

    Label lblprojID = (Label)GridView1.Rows[Index].FindControl("lblprojectID");
    Label lblpaydetails = (Label)GridView1.Rows[Index].FindControl("lblpaydetails");
    Label lblexpdate = (Label)GridView1.Rows[Index].FindControl("lblExpDate");
    Label lblexpttime = (Label)GridView1.Rows[Index].FindControl("lblExpTime");

    Label lblalloycodes = (Label)GridView1.Rows[Index].FindControl("lblalloycode");
    Label lblalloyrates = (Label)GridView1.Rows[Index].FindControl("lblalloyRate");
    Label lbladddelivered = (Label)GridView1.Rows[Index].FindControl("lbladdtodeliver");
    Label lblEID = (Label)GridView1.Rows[Index].FindControl("lblEID");

    ViewState["DispTime"] = lblttm.Text;
    ViewState["ExpTime"] = lblexpttime.Text;

    if (Operation == "Modify")
    {
        //lblchqNo.Text = txtchequeNO1.Text;
        //lblchqDate.Text = txtchequeDate1.Text;
        //lblAccountNo.Text = txtAccountNo.Text;
        //lblBName.Text = txtBankName.Text;
        lblddt.Text = txtdispdate.Text;

        if (ddldisphr.SelectedItem.Text == "00" & ddldispmin.SelectedItem.Text == "00" & ddldispsec.SelectedItem.Text == "00")
        {
            lblttm.Text = ViewState["DispTime"].ToString();

        }
        else
        {
            lblttm.Text = (ddldisphr.SelectedItem.Text + ":" + ddldispmin.SelectedItem.Text + ":" + ddldispsec.SelectedItem.Text);
        }

        if (ddlexphr.SelectedItem.Text == "00" & ddlexpmin.Text == "00" & ddlexpsec.Text == "00")
        {
            lblexpttime.Text = ViewState["ExpTime"].ToString();
        }
        else
        {
            lblexpttime.Text = (ddlexphr.SelectedItem.Text + ":" + ddlexpmin.Text + ":" + ddlexpsec.Text);
        }

        lblaeamt.Text = txtadvPayment.Text;

        lblpaydetails.Text = txtpaymentdetails.Text;
        lblexpdate.Text = txtexpdate.Text;

        lblalloycodes.Text = ddlalloycode.SelectedItem.Text;
        lblalloyrates.Text = txtalloyrate.Text;
        lbladddelivered.Text = txtaadtodel.Text;

        //ExecuteProcedures ex = new ExecuteProcedures(4);
        //string proc="Inse_Clientorder";
        //ex.Parameters.Add("@dtPayment_Date", SqlDbType.DateTime, lblddt.Text);
        //ex.Parameters.Add("@Dispath_Time", SqlDbType.VarChar, lblttm.Text);
        //ex.Parameters.Add("@Enquiry_ID", SqlDbType.VarChar, ID );
        //ex.Parameters.Add("@numAdvance_Amount", SqlDbType.Float , Convert.ToDouble(txtadvPayment.Text ));
        //bool s = ex.InvokeProcedure(proc);

        ExecuteProcedures ex = new ExecuteProcedures(12);
        //string proc = "Inse_Clientorder123";
        string proc = "Inse_Clientorder321";
        ex.Parameters.Add("@dtPayment_Date", SqlDbType.DateTime, Convert.ToDateTime(lblddt.Text));
        //if (ddldisphr.SelectedItem.Text == "00" & ddldispmin.SelectedItem.Text == "00" & ddldispsec.SelectedItem.Text == "00")
        //{
        //    ex.Parameters.Add("@Dispath_Time", SqlDbType.VarChar, ViewState["DispTime"]);

        //}
        //else
        //{
        //    ex.Parameters.Add("@Dispath_Time", SqlDbType.VarChar, lblttm.Text);
        //}

        //if (ddlexphr.SelectedItem.Text == "00" & ddlexpmin.Text == "00" & ddlexpsec.Text == "00")
        //{
        //    ex.Parameters.Add("@ExpTime", SqlDbType.VarChar, ViewState["ExpTime"]);
        //}
        //else 
        //{
        //    ex.Parameters.Add("@ExpTime", SqlDbType.VarChar, lblexpttime.Text);
        //}

        ex.Parameters.Add("@Dispath_Time", SqlDbType.VarChar, lblttm.Text);
        ex.Parameters.Add("@ExpTime", SqlDbType.VarChar, lblexpttime.Text);

        ex.Parameters.Add("@Advance_Payment_ID", SqlDbType.Int, Convert.ToInt32(lblid.Text));
        ex.Parameters.Add("@numAdvance_Amount", SqlDbType.VarChar, lblaeamt.Text);

        ex.Parameters.Add("@AlooyCode", SqlDbType.VarChar, lblalloycodes.Text);
        ex.Parameters.Add("@numRate", SqlDbType.Float, Convert.ToDouble(lblalloyrates.Text));
        ex.Parameters.Add("@vcrDescription", SqlDbType.VarChar, lbladddelivered.Text);
        ex.Parameters.Add("@Client_Ordered_Projects_ID", SqlDbType.Int, Convert.ToInt32(lblprojID.Text));
        ex.Parameters.Add("@Enquiry_ID", SqlDbType.Int, Convert.ToInt32(lblEID.Text));

        ex.Parameters.Add("@dtExpectedPayment_Date", SqlDbType.DateTime, Convert.ToDateTime(lblexpdate.Text));

        ex.Parameters.Add("@vcrPayment_Details", SqlDbType.VarChar, lblpaydetails.Text);

        bool s = ex.InvokeProcedure(proc);

        if (s == true)
        {
            CommonFunctions.Alert("Records Updated Successfully", this.Page);

        }
        else
        {
            CommonFunctions.Alert("Error In Updation", this.Page);
        }

        clear();

    }
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    //if (e.CommandName == "Modify")
    //{
    //    string strID = e.CommandArgument.ToString();
    //    strID = CommonFunctions.Encrypt(strID);
    //    Response.Redirect("Client_Order.aspx?Project_ID=" + strID);
    //}

    if (e.CommandName == "Modify")
    {

        string strID = e.CommandArgument.ToString();
        int intRowIndex = ((GridViewRow)((LinkButton)e.CommandSource).Parent.Parent).RowIndex;
        //Session[rowindex] = intRowIndex;
        txtdispdate.Text = GridView1.Rows[intRowIndex].Cells[6].Text;
        string strdisp = ((ddldisphr.SelectedItem.Text) + ":" + (ddldispmin.SelectedItem.Text) + ":" + (ddldispsec.SelectedItem.Text)).ToString();
        lbltime.Text = GridView1.Rows[intRowIndex].Cells[7].Text;
        Label lblClienorderiid = (Label)GridView1.Rows[intRowIndex].FindControl("lblcLOID");
        Label lbledate = (Label)GridView1.Rows[intRowIndex].FindControl("Label2");
        Label lbletime = (Label)GridView1.Rows[intRowIndex].FindControl("Label1");
        Label lbliid = (Label)GridView1.Rows[intRowIndex].FindControl("lblID");
        Label lblaamt = (Label)GridView1.Rows[intRowIndex].FindControl("lblamt");
        Label lblEID = (Label)GridView1.Rows[intRowIndex].FindControl("lblEID");

        Label lblprojID = (Label)GridView1.Rows[intRowIndex].FindControl("lblprojectID");
        Label lblpaydetails = (Label)GridView1.Rows[intRowIndex].FindControl("lblpaydetails");
        Label lblexpdate = (Label)GridView1.Rows[intRowIndex].FindControl("lblExpDate");
        Label lblexpttime = (Label)GridView1.Rows[intRowIndex].FindControl("lblExpTime");

        Label lblalloycodes = (Label)GridView1.Rows[intRowIndex].FindControl("lblalloycode");
        Label lblalloyrates = (Label)GridView1.Rows[intRowIndex].FindControl("lblalloyRate");
        Label lbladddelivered = (Label)GridView1.Rows[intRowIndex].FindControl("lbladdtodeliver");

        ViewState["Index"] = intRowIndex;
        ViewState["CommandName"] = e.CommandName;

        txtdispdate.Text = lbledate.Text;
        lbltime.Text = lbletime.Text;
        txtadvPayment.Text = lblaamt.Text;
        ddlalloycode.SelectedItem.Text = lblalloycodes.Text;
        txtalloyrate.Text = lblalloyrates.Text;
        txtaadtodel.Text = lbladddelivered.Text;
        txtpaymentdetails.Text = lblpaydetails.Text;
        txtexpdate.Text = lblexpdate.Text;
        lblexptimess.Text = lblexpttime.Text;

        pnl2.Visible = true;
        //lbltime.Text = lbltm.Text;

        //Add_Update_Remove_Row( intRowIndex , e.CommandName);
    }

    else if (e.CommandName == "Del")
    {
        string strID = e.CommandArgument.ToString();
        string strSql = "Delete from Client_Order where Client_ID = " + strID;
        string str_query = "Update Enquiry set OrderExecuted='No' where Enquiry_ID = " + strID;
        //string str_query = "delete from Enquiry  where Enquiry_ID = " + strID;
        Dentry de = new Dentry();
        de.RunCommand(strSql);
        de.RunCommand(str_query);
        Bind_Data();
    }     
    else if(e.CommandName =="Invoice")
    {
        string strID = e.CommandArgument.ToString();
        strID = CommonFunctions.Encrypt(strID);
        string strType = CommonFunctions.Encrypt("New");
        Response.Redirect("New_Order_Project_Invoice_Entry.aspx?Project_ID=" + strID + "&Type=" + strType);
    }
    else if (e.CommandName == "Delivered")
    {
        string strId = e.CommandArgument.ToString();
        string str_query = "Update Enquiry set vcrDelivered='Yes' where Enquiry_ID=" + strId;
        Dentry de = new Dentry();
        de.RunCommand(str_query);
        Bind_Data();
    }
}

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowIndex > -1)
    {
        LinkButton lnk = (LinkButton)e.Row.FindControl("lnkDelete");
        lnk.Attributes.Add("onClick", "return confirm('Are you sure to delete this record?');");
    }
}
protected void Add_Update_Remove_Row(int Index, string Operation)
{
    //DataTable dt = (DataTable)ViewState["Table_BinaryPayment"];

    int ID = Index;

    Label lblddt = (Label)GridView1.Rows[Index].FindControl("Label2");
    Label lblttm = (Label)GridView1.Rows[Index].FindControl("Label1");
    Label lblid = (Label)GridView1.Rows[Index].FindControl("lblID");
    Label lblaeamt = (Label)GridView1.Rows[Index].FindControl("lblamt");

    Label lblprojID = (Label)GridView1.Rows[Index].FindControl("lblprojectID");
    Label lblpaydetails = (Label)GridView1.Rows[Index].FindControl("lblpaydetails");
    Label lblexpdate = (Label)GridView1.Rows[Index].FindControl("lblExpDate");
    Label lblexpttime = (Label)GridView1.Rows[Index].FindControl("lblExpTime");

    Label lblalloycodes = (Label)GridView1.Rows[Index].FindControl("lblalloycode");
    Label lblalloyrates = (Label)GridView1.Rows[Index].FindControl("lblalloyRate");
    Label lbladddelivered = (Label)GridView1.Rows[Index].FindControl("lbladdtodeliver");
    Label lblEID = (Label)GridView1.Rows[Index].FindControl("lblEID");

    ViewState["DispTime"] = lblttm.Text;
    ViewState["ExpTime"] = lblexpttime.Text;

    if (Operation == "Modify")
    {
        //lblchqNo.Text = txtchequeNO1.Text;
        //lblchqDate.Text = txtchequeDate1.Text;
        //lblAccountNo.Text = txtAccountNo.Text;
        //lblBName.Text = txtBankName.Text;
        lblddt.Text = txtdispdate.Text;

        if (ddldisphr.SelectedItem.Text == "00" & ddldispmin.SelectedItem.Text == "00" & ddldispsec.SelectedItem.Text == "00")
        {
            lblttm.Text = ViewState["DispTime"].ToString();

        }
        else
        {
            lblttm.Text = (ddldisphr.SelectedItem.Text + ":" + ddldispmin.SelectedItem.Text + ":" + ddldispsec.SelectedItem.Text);
        }

        if (ddlexphr.SelectedItem.Text == "00" & ddlexpmin.Text == "00" & ddlexpsec.Text == "00")
        {
            lblexpttime.Text = ViewState["ExpTime"].ToString();
        }
        else
        {
            lblexpttime.Text = (ddlexphr.SelectedItem.Text + ":" + ddlexpmin.Text + ":" + ddlexpsec.Text);
        }

        lblaeamt.Text = txtadvPayment.Text;

        lblpaydetails.Text = txtpaymentdetails.Text;
        lblexpdate.Text = txtexpdate.Text;

        lblalloycodes.Text = ddlalloycode.SelectedItem.Text;
        lblalloyrates.Text = txtalloyrate.Text;
        lbladddelivered.Text = txtaadtodel.Text;

        //ExecuteProcedures ex = new ExecuteProcedures(4);
        //string proc="Inse_Clientorder";
        //ex.Parameters.Add("@dtPayment_Date", SqlDbType.DateTime, lblddt.Text);
        //ex.Parameters.Add("@Dispath_Time", SqlDbType.VarChar, lblttm.Text);
        //ex.Parameters.Add("@Enquiry_ID", SqlDbType.VarChar, ID );
        //ex.Parameters.Add("@numAdvance_Amount", SqlDbType.Float , Convert.ToDouble(txtadvPayment.Text ));
        //bool s = ex.InvokeProcedure(proc);

        ExecuteProcedures ex = new ExecuteProcedures(12);
        //string proc = "Inse_Clientorder123";
        string proc = "Inse_Clientorder321";
        ex.Parameters.Add("@dtPayment_Date", SqlDbType.DateTime, Convert.ToDateTime(lblddt.Text));
        //if (ddldisphr.SelectedItem.Text == "00" & ddldispmin.SelectedItem.Text == "00" & ddldispsec.SelectedItem.Text == "00")
        //{
        //    ex.Parameters.Add("@Dispath_Time", SqlDbType.VarChar, ViewState["DispTime"]);

        //}
        //else
        //{
        //    ex.Parameters.Add("@Dispath_Time", SqlDbType.VarChar, lblttm.Text);
        //}

        //if (ddlexphr.SelectedItem.Text == "00" & ddlexpmin.Text == "00" & ddlexpsec.Text == "00")
        //{
        //    ex.Parameters.Add("@ExpTime", SqlDbType.VarChar, ViewState["ExpTime"]);
        //}
        //else 
        //{
        //    ex.Parameters.Add("@ExpTime", SqlDbType.VarChar, lblexpttime.Text);
        //}

        ex.Parameters.Add("@Dispath_Time", SqlDbType.VarChar, lblttm.Text);
        ex.Parameters.Add("@ExpTime", SqlDbType.VarChar, lblexpttime.Text);

        ex.Parameters.Add("@Advance_Payment_ID", SqlDbType.Int, Convert.ToInt32(lblid.Text));
        ex.Parameters.Add("@numAdvance_Amount", SqlDbType.VarChar, lblaeamt.Text);

        ex.Parameters.Add("@AlooyCode", SqlDbType.VarChar, lblalloycodes.Text);
        ex.Parameters.Add("@numRate", SqlDbType.Float, Convert.ToDouble(lblalloyrates.Text));
        ex.Parameters.Add("@vcrDescription", SqlDbType.VarChar, lbladddelivered.Text);
        ex.Parameters.Add("@Client_Ordered_Projects_ID", SqlDbType.Int, Convert.ToInt32(lblprojID.Text));
        ex.Parameters.Add("@Enquiry_ID", SqlDbType.Int, Convert.ToInt32(lblEID.Text));

        ex.Parameters.Add("@dtExpectedPayment_Date", SqlDbType.DateTime, Convert.ToDateTime(lblexpdate.Text));

        ex.Parameters.Add("@vcrPayment_Details", SqlDbType.VarChar, lblpaydetails.Text);

        bool s = ex.InvokeProcedure(proc);

        if (s == true)
        {
            CommonFunctions.Alert("Records Updated Successfully", this.Page);

        }
        else
        {
            CommonFunctions.Alert("Error In Updation", this.Page);
        }

        clear();

    }
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    //if (e.CommandName == "Modify")
    //{
    //    string strID = e.CommandArgument.ToString();
    //    strID = CommonFunctions.Encrypt(strID);
    //    Response.Redirect("Client_Order.aspx?Project_ID=" + strID);
    //}

    if (e.CommandName == "Modify")
    {

        string strID = e.CommandArgument.ToString();
        int intRowIndex = ((GridViewRow)((LinkButton)e.CommandSource).Parent.Parent).RowIndex;
        //Session[rowindex] = intRowIndex;
        txtdispdate.Text = GridView1.Rows[intRowIndex].Cells[6].Text;
        string strdisp = ((ddldisphr.SelectedItem.Text) + ":" + (ddldispmin.SelectedItem.Text) + ":" + (ddldispsec.SelectedItem.Text)).ToString();
        lbltime.Text = GridView1.Rows[intRowIndex].Cells[7].Text;
        Label lblClienorderiid = (Label)GridView1.Rows[intRowIndex].FindControl("lblcLOID");
        Label lbledate = (Label)GridView1.Rows[intRowIndex].FindControl("Label2");
        Label lbletime = (Label)GridView1.Rows[intRowIndex].FindControl("Label1");
        Label lbliid = (Label)GridView1.Rows[intRowIndex].FindControl("lblID");
        Label lblaamt = (Label)GridView1.Rows[intRowIndex].FindControl("lblamt");
        Label lblEID = (Label)GridView1.Rows[intRowIndex].FindControl("lblEID");

        Label lblprojID = (Label)GridView1.Rows[intRowIndex].FindControl("lblprojectID");
        Label lblpaydetails = (Label)GridView1.Rows[intRowIndex].FindControl("lblpaydetails");
        Label lblexpdate = (Label)GridView1.Rows[intRowIndex].FindControl("lblExpDate");
        Label lblexpttime = (Label)GridView1.Rows[intRowIndex].FindControl("lblExpTime");

        Label lblalloycodes = (Label)GridView1.Rows[intRowIndex].FindControl("lblalloycode");
        Label lblalloyrates = (Label)GridView1.Rows[intRowIndex].FindControl("lblalloyRate");
        Label lbladddelivered = (Label)GridView1.Rows[intRowIndex].FindControl("lbladdtodeliver");

        ViewState["Index"] = intRowIndex;
        ViewState["CommandName"] = e.CommandName;

        txtdispdate.Text = lbledate.Text;
        lbltime.Text = lbletime.Text;
        txtadvPayment.Text = lblaamt.Text;
        ddlalloycode.SelectedItem.Text = lblalloycodes.Text;
        txtalloyrate.Text = lblalloyrates.Text;
        txtaadtodel.Text = lbladddelivered.Text;
        txtpaymentdetails.Text = lblpaydetails.Text;
        txtexpdate.Text = lblexpdate.Text;
        lblexptimess.Text = lblexpttime.Text;

        pnl2.Visible = true;
        //lbltime.Text = lbltm.Text;

        //Add_Update_Remove_Row( intRowIndex , e.CommandName);
    }

    else if (e.CommandName == "Del")
    {
        string strID = e.CommandArgument.ToString();
        string strSql = "Delete from Client_Order where Client_ID = " + strID;
        string str_query = "Update Enquiry set OrderExecuted='No' where Enquiry_ID = " + strID;
        //string str_query = "delete from Enquiry  where Enquiry_ID = " + strID;
        Dentry de = new Dentry();
        de.RunCommand(strSql);
        de.RunCommand(str_query);
        Bind_Data();
    }     
    else if(e.CommandName =="Invoice")
    {
        string strID = e.CommandArgument.ToString();
        strID = CommonFunctions.Encrypt(strID);
        string strType = CommonFunctions.Encrypt("New");
        Response.Redirect("New_Order_Project_Invoice_Entry.aspx?Project_ID=" + strID + "&Type=" + strType);
    }
    else if (e.CommandName == "Delivered")
    {
        string strId = e.CommandArgument.ToString();
        string str_query = "Update Enquiry set vcrDelivered='Yes' where Enquiry_ID=" + strId;
        Dentry de = new Dentry();
        de.RunCommand(str_query);
        Bind_Data();
    }
}

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowIndex > -1)
    {
        LinkButton lnk = (LinkButton)e.Row.FindControl("lnkDelete");
        lnk.Attributes.Add("onClick", "return confirm('Are you sure to delete this record?');");
    }
}
陪你搞怪i 2024-10-13 08:34:20

启用 View State= true 将解决您的问题

Enable View State= true will solve your problem

我要还你自由 2024-10-13 08:34:19

您的 gridview 没有在其标记中连接事件。

尝试添加 onrowcommand="GridViewProducts_RowCommand" ,如下所示:

<asp:GridView ID="GridViewProducts" runat="server" AutoGenerateColumns="False" 
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" 
CellPadding="5" CellSpacing="1" DataKeyNames="Pkey" 
DataSourceID="SqlDataSourceProducts" ForeColor="Black" GridLines="Vertical"
onrowcommand="GridViewProducts_RowCommand">

Your gridview doesnt have the event wired up in its markup.

Try adding in onrowcommand="GridViewProducts_RowCommand" so it looks like this:

<asp:GridView ID="GridViewProducts" runat="server" AutoGenerateColumns="False" 
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" 
CellPadding="5" CellSpacing="1" DataKeyNames="Pkey" 
DataSourceID="SqlDataSourceProducts" ForeColor="Black" GridLines="Vertical"
onrowcommand="GridViewProducts_RowCommand">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文