what was error in Mycode?

Posted by Raghuldrag under C# on 5/28/2013 | Points: 10 | Views : 700 | Status : [Member] | Replies : 2
Hai Friends,
In My application 've the input fields of


INPUT FIELDS
==================
Name:textbox
class:dropdownlist

add(button)

after adding the details ll display on Gridview's.

i ve already done these much!
my requirement is when i choose edit in gridview's entire details ll shown on above input fields.



so i made the query like these



protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;

for (int i = 0; i < GridView1.Rows.Count; i++)
{
string id = GridView1.Rows[i].Cells[1].Text;===>error
string name = ((TextBox)GridView1.Rows[i].FindControl("txtname")).Text;
string clas = ((DropDownList)GridView1.Rows[i].FindControl("DDL_Class")).ToString();






}
binddata();
}


when i debug the code ll show error like this

"Object reference not set to an instance of an object." in GridView1_RowEditing string id,string name,string clas


i dont know what was the problem in that?

Anybody can explain me and guideme.




Responses

Posted by: Ankitsrist on: 5/28/2013 [Member] Starter | Points: 25

Up
0
Down
have you mentioned DataKeyName in your gridview control?

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 5/28/2013 [Member] Starter | Points: 25

Up
0
Down
int id = Convert.ToInt32(GridView1.DataKeys [e.RowIndex].Value.ToString());

TextBox txtname= (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtname");
DropDownList DDL_Class= (TextBox)GridView1.Rows[e.RowIndex].FindControl("DDL_Class");

use this


Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response