单击Gridview内的RowCommand按钮后,页面变为空白 [英] Page becomes blank after click on the RowCommand Button inside the Gridview

查看:123
本文介绍了单击Gridview内的RowCommand按钮后,页面变为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,我的代码中存在问题。我正在做gridview插入,更新,删除事件程序。

我拿了一个页脚并在

中显示了两个文本框和一个添加按钮我已绑定gridview.and显示在正确的webform1.aspx和RowCommand事件。

当我点击添加按钮,从Gridview的行中将值插入到我的表中。所以我当前的页面变成空白。一切都变得隐藏在当前页面之外。为什么???



我的代码是

Dear friends I have a issue in my codes. I am doing gridview insert ,update,delete events program.
I took one footer and displayed two textboxs and one Add button in the
I have bound gridview.and displayed on the webform1.aspx properly.and on the RowCommand Event.
When I click on the add button for insert the values into my table from the Gridview’s rows. So my current page becomes blank. And everything becomes hide from the current page . why ???

My code are

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (!IsPostBack)
            if (e.CommandName == "ADD")
            {


                Button Button1 = (Button)GridView1.FooterRow.FindControl("Button1");
                TextBox txtfooterid = (TextBox)GridView1.FooterRow.FindControl("txtfooterid");
                TextBox txtfootername = (TextBox)GridView1.FooterRow.FindControl("txtfootername");
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("insert into tab1(id,name) values('"+txtfooterid.Text+"','"+txtfootername.Text+"')", con);
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }

推荐答案

当你的页面获得回发时,所以当页面获得回发时,新的对象是页面来自服务器,这就是为什么它变空。所以在pageload事件中检查页面的回发属性并做任何你想做的事。
As your page is getting postback so when page gets postback a new object of the page comes from the server that's why it is getting empty.So check the postback property of the page in pageload event and do whatever you want.


这篇关于单击Gridview内的RowCommand按钮后,页面变为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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