Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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();
            }
        }
Posted
Updated 13-Jan-15 17:10pm
v2

1 solution

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.
 
Share this answer
 
Comments
faizyab 2009 15-Jan-15 15:49pm    
if i add values inside the row so add button is working but row does not show at that time. but if i close the page and again reload then added values display. why thd is thing happening . and i have checked page_load() and postback event
MohitMunjal 16-Jan-15 4:34am    
please fill the grid again on the button click then you will get the updated grid.
post your code also so that i can check where the error is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900