Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have two textbox, one button and one gridview what i want is when user enter details in those two textbox and press on submit button it will show in the gridview. In my grid i have an edit link so that when i click on edit link that row data can be seen in those two textboxes using query string and submit button change to update button and after making some changes when user click on update button it will update data in the grid and database too

here what i have done till yet

C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindGrid();
            string ID = Request.QueryString["ID"];
            cmd = new SqlCommand("Select * from UserDetails where ID='" + ID + "'", con);
            con.Open();
            ad = new SqlDataAdapter(cmd);
            dt.Clear();
            ad.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                tbid.Text = ID;
                TextBox1.Text = dt.Rows[0][1].ToString();
                TextBox2.Text = dt.Rows[0][2].ToString();
            }
            con.Close();
        }
    }


C#
protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Test;Integrated Security=True");
        con.Open();

        string Name = TextBox1.Text;
        string Place = TextBox2.Text;

        using (SqlCommand cmd = con.CreateCommand())
        {
            cmd.CommandText = "insert into UserDetails(Name,Place) values('" + Name + "','" + Place + "')";
            cmd.Parameters.AddWithValue("@Name", TextBox1.Text);
            cmd.Parameters.AddWithValue("@Place", TextBox2.Text);
            cmd.ExecuteNonQuery();
        }
        con.Close();
        GridView1.DataSource = dt;
        GridView1.DataBind();
        TextBox1.Text = string.Empty;
        TextBox2.Text = string.Empty;
        }
    private void BindGrid()
    {
        con.Open();
        ad = new SqlDataAdapter("Select * from UserDetails where Name=Name", con);
        ad.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        con.Close();
    }
}



when user enter some data in the input field it will store in the database but it will not instantly show in the grid
second think when i click on edit link my data will be shown in the textboxex using query string but now i want to update that data but i want to use same submit button with text change to update after click on edit link
Posted
Comments
Rockstar_ 19-Apr-13 5:12am    
Don't write story dear...
Ask questions like where u stuck?
amitesh1989 19-Apr-13 6:07am    
i wont be able show next data when page load in grid-view when i enter details in text-boxes and press submit button

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