FindControl Method always returns empty string!!!!!

S

steroche

Hi guys - Can somebody please help me?
I'm a novice at all thisIve run into a serious stumbling block for the
last few hours now and its killing me!
I have a paged/sorted Datagrid setup and it works fine except for the
update method - i just cannot get it to work!
Now i keep getting the error :

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object
on line
Line 486: this.dsGarda.Tables["Garda"].Rows[e.Item.ItemIndex][3]
= newCaseID;

Here is my update method:

private void dgGarda_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string newCaseID, newStationID = null;
string newLname,newRank,newArea = null;

TextBox tb;
//all tb.Text vals = "" below
tb =
(TextBox)(dgGarda.Items[dgGarda.EditItemIndex].FindControl("txtEditCase"));
newCaseID = tb.Text.ToString();
tb =
(TextBox)(dgGarda.Items[dgGarda.EditItemIndex].FindControl("txtEditStation"));
newStationID = tb.Text;
tb =
(TextBox)(dgGarda.Items[dgGarda.EditItemIndex].FindControl("txtEditRank"));
newRank = tb.Text;
tb =
(TextBox)(dgGarda.Items[dgGarda.EditItemIndex].FindControl("txtEditArea"));
newArea = tb.Text;

this.dsGarda.Tables[1].Rows[e.Item.ItemIndex][3] = newCaseID;
this.dsGarda.Tables["Garda"].Rows[e.Item.ItemIndex][4] = newStationID;
this.dsGarda.Tables["Garda"].Rows[e.Item.ItemIndex][5] =
newRank;this.dsGarda.Tables["Garda"].Rows[e.Item.ItemIndex][6] =
newArea;

this.daGarda.Update(dsGarda, "Garda");
dgCase.EditItemIndex = -1;
dgCase.DataBind();
}

When i step through the code i see that all my FindControl methods are
returning empty strings aswell!!Anybody have any idea whats going on??I
read somewhere i should have the datagrid.databind call in the if
(!IsPostBack) but when i did this it didn't reload the grid when i
clicked edit.

Any help is greatly appreciated as i think i am going to kill my
computer shortly if i cant fix this!!!

Thanks,
Steve
 
S

steroche

One problem down, was rebinding old data each time i went to upload- in
the DataGrid1_EditCommand - which is odd,didn't think that would effect
the subsequent DataGrid1_UpdateCommand but evidently it does!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top