I am trying to create a fully editable gridview. the gridview is bound when a item is selected from a dropdown list.
protected void bindgridview()
{
PlayerStatEntryTableAdapters.DataTable1TableAdapter statEntryAdapter = new PlayerStatEntryTableAdapters.DataTable1TableAdapter();
GridView1.DataSource = statEntryAdapter.GetData(int.Parse(ddlGames.SelectedValue.ToString()));
GridView1.DataBind();
}
When the row is created I add a textbox control to each of the editable cells and populate the textbox with the value of the cell
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Visible = false;
e.Row.Cells[3].Visible = false;
int i = 4;
while (i < 37)
{
System.Web.UI.WebControls.TextBox tb = new System.Web.UI.WebControls.TextBox();
tb.Text = e.Row.Cells.Text.ToString();
tb.MaxLength = 2;
tb.Width = 12;
tb.Font.Size = 7;
tb.ID = "tb";
e.Row.Cells.Controls.Add(tb);
i++;
}
}
}
There is a single save button that i use to update the database. It loops through each row and should update using the values in the textbox control.
The text in the cell is still the value pulled from the database, not the text that the user has entered.
I cant figure out how to access the value in the textbox.
SqlConnection db = new SqlConnection("server=DATABASE;integrated security=true;" + "database=db");
SqlCommand insrtPlayer = new SqlCommand("insrtPlayer", cnPubs);
insrtPlayer.CommandText = "update dr_game_stats set b_pa = " + GridView1.Rows.Cells[4].Text.ToString() + ", b_sing = " + GridView1.Rows.Cells[5].Text.ToString();
db.Open();
insrtPlayer.ExecuteNonQuery();
db.Close();
i++;
}
Any suggestions?
Thanks
d
protected void bindgridview()
{
PlayerStatEntryTableAdapters.DataTable1TableAdapter statEntryAdapter = new PlayerStatEntryTableAdapters.DataTable1TableAdapter();
GridView1.DataSource = statEntryAdapter.GetData(int.Parse(ddlGames.SelectedValue.ToString()));
GridView1.DataBind();
}
When the row is created I add a textbox control to each of the editable cells and populate the textbox with the value of the cell
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Visible = false;
e.Row.Cells[3].Visible = false;
int i = 4;
while (i < 37)
{
System.Web.UI.WebControls.TextBox tb = new System.Web.UI.WebControls.TextBox();
tb.Text = e.Row.Cells.Text.ToString();
tb.MaxLength = 2;
tb.Width = 12;
tb.Font.Size = 7;
tb.ID = "tb";
e.Row.Cells.Controls.Add(tb);
i++;
}
}
}
There is a single save button that i use to update the database. It loops through each row and should update using the values in the textbox control.
The text in the cell is still the value pulled from the database, not the text that the user has entered.
I cant figure out how to access the value in the textbox.
SqlConnection db = new SqlConnection("server=DATABASE;integrated security=true;" + "database=db");
SqlCommand insrtPlayer = new SqlCommand("insrtPlayer", cnPubs);
insrtPlayer.CommandText = "update dr_game_stats set b_pa = " + GridView1.Rows.Cells[4].Text.ToString() + ", b_sing = " + GridView1.Rows.Cells[5].Text.ToString();
db.Open();
insrtPlayer.ExecuteNonQuery();
db.Close();
i++;
}
Any suggestions?
Thanks
d