954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SOS - datagrid problem

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
}
}
c# seeker
Newbie Poster
7 posts since Feb 2007
Reputation Points: 10
Solved Threads: 1
 

Which event is this code running from?
Did you trace with Studio (debug)?

nikkiH
Junior Poster in Training
79 posts since Dec 2006
Reputation Points: 13
Solved Threads: 4
 

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.

c# seeker
Newbie Poster
7 posts since Feb 2007
Reputation Points: 10
Solved Threads: 1
 

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.

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You