Gridview删除按钮代码 [英] Gridview delete button code

查看:74
本文介绍了Gridview删除按钮代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们...

在我的项目中,我试图使用Ajax Modal Popup扩展程序删除gridview数据...我设计了它,但是我不知道如何编写Delete按钮Click事件的代码...

Hi frnds...

In my project i am trying to delete the gridview data with the use of Ajax Modal Popup extender... I designed it but i dont know how to write the code for Delete button Click event...

<asp:TemplateField HeaderText="Delete">
                           <ItemTemplate>
                               <asp:ImageButton ID="Imgdelete" runat="server" CommandName="Delete" OnClientClick="showConfirm(this); return false;"

                                   ImageUrl="~/admin/Images/Delete.gif" Width="15px" />
                           </ItemTemplate>
                       </asp:TemplateField>

<script language="javascript" type="text/javascript">
    var _source;
    var _popup;
    
    function showConfirm(source)
    {
        this._source = source;
        this._popup=$find('mdlpopup');         
        this._popup.show();
    }
    
    function okClick()
    {
        this._popup.hide();                
        __doPostBack(this._source.name, '');        
    }
    
    function cancelClick()
    {
        this._popup.hide();
        this._source=null;
        this._popup=null;
    }


我设计了以上代码...谁能帮我在按钮单击事件中编写代码...

我写了这段代码..但是我的参数超出了范围异常//


i designed the above code... can anyone help me to write code in button click event...

i wrote this code.. but i am getting argument out of range exception//

protected void Imgdelete_Click(object sender, EventArgs e)
    {
        ImageButton btndelete = sender as ImageButton;
        GridViewRow row = (GridViewRow)btndelete.NamingContainer;

        //string productname = Convert.ToString(btndelete.CommandArgument);
        string productname = Convert.ToString(Quote_Grid.DataKeys[row.RowIndex].Value.ToString());
        string Productname = row.Cells[0].Text;

        con.Open();
        cmd = new SqlCommand("Delete from Quote_pro_details where p_name='" + productname + "' and Quote_ID='" + txtquoteid.Text + "'", con);
        int result = cmd.ExecuteNonQuery();
        con.Close();
        if (result == 1)
        {
            Quote_Grid_Bind();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + productname + "details deleted successfully')", true);
        }

    }

推荐答案

find('mdlpopup'); this._popup.show(); } 函数okClick() { this._popup.hide(); __doPostBack(this._source.name,``); } 函数cancelClick() { this._popup.hide(); this._source = null; this._popup = null; }
find('mdlpopup'); this._popup.show(); } function okClick() { this._popup.hide(); __doPostBack(this._source.name, ''); } function cancelClick() { this._popup.hide(); this._source=null; this._popup=null; }


我设计了以上代码...谁能帮我在按钮单击事件中编写代码...

我写了这段代码..但是我的参数超出了范围异常//


i designed the above code... can anyone help me to write code in button click event...

i wrote this code.. but i am getting argument out of range exception//

protected void Imgdelete_Click(object sender, EventArgs e)
    {
        ImageButton btndelete = sender as ImageButton;
        GridViewRow row = (GridViewRow)btndelete.NamingContainer;

        //string productname = Convert.ToString(btndelete.CommandArgument);
        string productname = Convert.ToString(Quote_Grid.DataKeys[row.RowIndex].Value.ToString());
        string Productname = row.Cells[0].Text;

        con.Open();
        cmd = new SqlCommand("Delete from Quote_pro_details where p_name='" + productname + "' and Quote_ID='" + txtquoteid.Text + "'", con);
        int result = cmd.ExecuteNonQuery();
        con.Close();
        if (result == 1)
        {
            Quote_Grid_Bind();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + productname + "details deleted successfully')", true);
        }

    }




试试这个:

在您的客户代码中:

Hi,

Try this:

In your client code:

   <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Delete">
  <HeaderTemplate>Delete</HeaderTemplate>
     <ItemTemplate>
        <asp:ImageButton ID="Imgdelete" runat="server" 
        ImageUrl="~/admin/Images/Delete.gif" ToolTip="Delete product" 
        onclick="Imgdelete_Click" OnClientClick="return confirm(''Delete this record?'');"  />
     </ItemTemplate>
  <FooterTemplate></FooterTemplate>
</asp:TemplateField>



在您后面的代码中:



In your code behind:

   protected void Imgdelete_Click(object sender, ImageClickEventArgs e)
{
    GridViewRow row = (GridViewRow)Imgdelete.NamingContainer;
    string productName = row.Cells[0].Text;
    string quoteID  = txtquoteid.Text;
    
    //...Some code here...
    cmd = new SqlCommand("Delete from Quote_pro_details where p_name=''" + 
          productName + "'' and Quote_ID=''" + quoteID + "''", con);
    //... Some Code here...
     
}

Hope this could help:

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem


这篇关于Gridview删除按钮代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆