Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
 
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();
        }
    }
 
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 18-Apr-13 23:23pm
Comments
Member61 at 19-Apr-13 5:12am
   
Don't write story dear...
Ask questions like where u stuck?
amitesh1989 at 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)

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 BillWoodruff 220
4 Mathew Soji 195
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,817
2 DamithSL 5,461
3 Manas Bhardwaj 4,946
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 19 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100