I'm using the following code to pass data to a table in my database. The datagrid consists of a bound column and 3 template columns (2 textboxes and a chackebox).

The problem is that the values of these template columns cannot be read. (i.e. in the following code, values of qtyTextBox and desTextBox are "" and addChackBox.Checked is always 'false' even if it is checked).

HELP!!!

for (int i = 0; i < dgaddf.Items.Count; i++)
{
DataGridItem item = dgaddf.Items[i];
string it = item.Cells[1].Text.ToString();
TextBox qtyTextBox (TextBox)item.FindControl("txtQ");
TextBox desTextBox=(TextBox)item.FindControl("txtD");
CheckBox addCheckBox = (CheckBox)item.FindControl("Chk1");
if (addCheckBox.Checked)
{
br.createFloRec(it, int.Parse(qtyTextBox.Text), desTextBox.Text, connect1.con); 
// the function that adds data to the DB
}
}

I've traced it with debug but it doesn't show any error. But the data is nt added to the database.

The coding is triggered by the event handler of a button (which is outside the datagrid).

Tried everything possible. Couldn't find a solution. So opted for a dynamic table rather than a datagrid.

How was your datagrid boiund? in the Page_Load? if so is it inside an if(!IsPostBack) statement block? if it isn't it will be rebound (everything reset to previous values) on postback BEFORE the click event fires.

This article has been dead for over six months. Start a new discussion instead.