在gridview中,我添加了一个动态按钮作为"REVISE".... [英] in gridview i have added a dynamic button as "REVISE"....

查看:68
本文介绍了在gridview中,我添加了一个动态按钮作为"REVISE"....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在gridview中,我添加了一个动态按钮作为"REVISE".
现在我想要的是当我单击此按钮时,应使用两个按钮将新的ROW插入到gridview所单击的行的下方."YES"和"NO"

在这里,我向您提供代码.我已经编码了,但是我没有得到想要的东西,
请帮助

 公共 部分  class  RenewDocuments:System.Web.UI.Page
{

    SqlConnection cn =  SqlConnection(" );
    SqlDataAdapter sda;
    数据集ds;
     int  ID;

    受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
    {
        cn.Open();
       
            FillData();
    }

    公共 无效 FillData()
    {
        // 用于获取2天之间的记录的代码

        字符串 str = " ;
        SqlCommand cmd =  SqlCommand(str,cn);
        cmd.Parameters.Add(" ,SqlDbType.Date).Value = DateTime.Now;

        sda =  SqlDataAdapter();
        sda.SelectCommand = cmd;

        ds =  DataSet();
        sda.Fill(ds);

        如果(ds ==  || ds.Tables [ 0 ].Rows.Count ==  0 )// " ;
        }
        其他
        {
            
            cn.Close();
            sda.Dispose();

            // 在数据表中添加两列.
            ds.Tables [ 0 ].Columns.Add(" );
           

            GVRenewalDocuments.DataSource = ds;
            GVRenewalDocuments.DataBind();
        }
    }

    受保护的 无效 GVRenewalDocuments_RowDataBound( object 发​​件人,GridViewRowEventArgs e)
    {

        // 添加按钮
        Button rev =  Button();
        rev.Text = " ;

        // 分配命令名称
        rev.CommandName = " ;
        

        如果(例如,Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells [ 10 ].Controls.Add(rev);
        }
    }

    受保护的 无效 GVRenewalDocuments_RowCommand(对象发​​件人,GridViewCommandEventArgs e)
    {
        如果(例如CommandName == " 跨度>)
        {
            GridViewRow row =(GridViewRow)((Control)e.CommandSource).NamingContainer;
            ID = Convert.ToInt32(GVRenewalDocuments.DataKeys [row.RowIndex] .Value.ToString());
            DataTable dt = ds.Tables [ 0 ];  // 这就是我要做的事情 DataRow row1 = dt.NewRow(); 

            dt.Rows.Add(row1);

            GVRenewalDocuments.DataSource = dt;
            GVRenewalDocuments.DataBind();

            //  AddNewRow(); 
                     
           Response.Redirect(Request.RawUrl); // 此行用于刷新页面,而无需使用"response.redirect" 
        }
    }
} 

解决方案

通过下面的链接进行操作,这将对您有所帮助

http://www. aspsnippets.com/Articles/Save-and-Retrieve-Dynamic-TextBox-values-in-GridView-to-SQL-Server-Database.aspx [ now what i want is when i click on this button, A new ROW should be inserted below the clicked row of gridview with the two buttons.. "YES" and "NO"

here i m providing u the code. which i have coded but i m not getting what i want,
Please Help

public partial class RenewDocuments : System.Web.UI.Page
{

    SqlConnection cn = new SqlConnection("Data Source=FRE-GGN-MSSTEST;Initial Catalog=DMS1;Integrated Security=True");
    SqlDataAdapter sda;
    DataSet ds;
    int Id;

    protected void Page_Load(object sender, EventArgs e)
    {
        cn.Open();
       
            FillData();
    }

    public void FillData()
    {
        // code for getting the records that are between 2 days period

        string str = "select * from tdocument where @tdy between upload_date and expire_date";
        SqlCommand cmd = new SqlCommand(str, cn);
        cmd.Parameters.Add("@tdy", SqlDbType.Date).Value = DateTime.Now;

        sda = new SqlDataAdapter();
        sda.SelectCommand = cmd;

        ds = new DataSet();
        sda.Fill(ds);

        if (ds == null || ds.Tables[0].Rows.Count == 0)  // condition that checks whether there is any records or not
        {
            LblNoRecords.Text = "No Records have been Uploaded Recently";
        }
        else
        {
            
            cn.Close();
            sda.Dispose();

            //Adding two columns in datatable.
            ds.Tables[0].Columns.Add("REVISE");
           

            GVRenewalDocuments.DataSource = ds;
            GVRenewalDocuments.DataBind();
        }
    }

    protected void GVRenewalDocuments_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        //Adding the buttons
        Button rev = new Button();
        rev.Text = "Revise";        

        //assignnig command name
        rev.CommandName = "REVISE";
        

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[10].Controls.Add(rev);            
        }
    }

    protected void GVRenewalDocuments_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "REVISE")
        {
            GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
            Id = Convert.ToInt32(GVRenewalDocuments.DataKeys[row.RowIndex].Value.ToString()); 
            DataTable dt = ds.Tables[0];     // THIS IS WHAT I HAVE DONE            DataRow row1 = dt.NewRow();

            dt.Rows.Add(row1);

            GVRenewalDocuments.DataSource = dt;
            GVRenewalDocuments.DataBind();

            //AddNewRow();                          
                     
           Response.Redirect(Request.RawUrl);    // this line is to refresh the page without using "response.redirect"
        }      
    }
}

解决方案

go through below link this will help you

http://www.aspsnippets.com/Articles/Save-and-Retrieve-Dynamic-TextBox-values-in-GridView-to-SQL-Server-Database.aspx[^]


这篇关于在gridview中,我添加了一个动态按钮作为"REVISE"....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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