retrieve the cell value from the gridview but it returns null
-
Is your page load interacting with your grid at all ? If you look at this code in the debugger, do any of the cells have data for that row ? For any row ? Tell me it's not really called gridview1 ???
Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
Christian Graus wrote:
Tell me it's not really called gridview1 ???
:) . Last week I was invited to one company for checking their code and giving some advice for their project. I can see a gridview named as gridView256 ! The page which they wrote contained 256 gridviews and all named like gridview1 .. 256. What a disaster !
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
hi all, I just want to retrieve the cell value from the gridview using the following code,but it returns nothing null plz help me protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; //here to delete in data base //the problem in the next code this string (spareid)carry null string spareid = GridView1.Rows[index].Cells[0].ToString(); new DataAccess.Service().SparePart_Delete(spareid); //here to delete in dataset to reflect in gridview DataSet ds = (DataSet)Session["dataset"]; ds.Tables[0].Rows[index].Delete(); GridView1.DataSource = ds; GridView1.DataBind(); //here notification for delete lblmsg.Text = "delete ok "; lblmsg.Visible = true; } plz help me i dont know where is the error thanks in advice
Kareem Elhosseny
I also face that type problem. at that time i change the cell index even the original cell index is =0, Try this ..
-
my friend Christian :rose:; I have a user controle which carry this gridview and use it in the aspx page is this case cause any problem i dont know where is the error and why it carry null :(( :(( :confused:
Kareem Elhosseny
No, that won't cause it, perhaps you could answer my questions ?
Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
-
hi all, I just want to retrieve the cell value from the gridview using the following code,but it returns nothing null plz help me protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; //here to delete in data base //the problem in the next code this string (spareid)carry null string spareid = GridView1.Rows[index].Cells[0].ToString(); new DataAccess.Service().SparePart_Delete(spareid); //here to delete in dataset to reflect in gridview DataSet ds = (DataSet)Session["dataset"]; ds.Tables[0].Rows[index].Delete(); GridView1.DataSource = ds; GridView1.DataBind(); //here notification for delete lblmsg.Text = "delete ok "; lblmsg.Visible = true; } plz help me i dont know where is the error thanks in advice
Kareem Elhosseny
Are you binding the grid in the page load ? make sure you are doing it inside "!IsPostBack" blocks.
elhosseny wrote:
string spareid = GridView1.Rows[index].Cells[0].ToString();
It's not safe to do the above. "Rows[index]" returns a row instance which may be NULL or the cell may be NULL. Check it is NULL, if not proceed with delete.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Christian Graus wrote:
Tell me it's not really called gridview1 ???
:) . Last week I was invited to one company for checking their code and giving some advice for their project. I can see a gridview named as gridView256 ! The page which they wrote contained 256 gridviews and all named like gridview1 .. 256. What a disaster !
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
im not using any server controls
with regards, bretto
-
Are you binding the grid in the page load ? make sure you are doing it inside "!IsPostBack" blocks.
elhosseny wrote:
string spareid = GridView1.Rows[index].Cells[0].ToString();
It's not safe to do the above. "Rows[index]" returns a row instance which may be NULL or the cell may be NULL. Check it is NULL, if not proceed with delete.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
ok i'll change the gridview name is it the solve for my problem where the solution ???????????????????????????????????????????????????????????????????????????????????????
Kareem Elhosseny
Try This String Str = GridView1.Rows[e.RowIndex].Cells[0].Text;
Bharani
-
No, that won't cause it, perhaps you could answer my questions ?
Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
-
Try This String Str = GridView1.Rows[e.RowIndex].Cells[0].Text;
Bharani
-
is there a problem when i make all column as a templet filed is this make the problem
Kareem Elhosseny
No, There wont be any problem if u Made all the field to be template
Bharani
-
Dear friend; my question why the cell carry null value ? i make all solution but it also carry null
Kareem Elhosseny
I can't answer you, because I asked you questions to try to work out the problem and you did not answer them.
Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
-
ok i'll change the gridview name is it the solve for my problem where the solution ???????????????????????????????????????????????????????????????????????????????????????
Kareem Elhosseny
The name just makes your code readable, it plainly won't solve the issue
Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
-
The name just makes your code readable, it plainly won't solve the issue
Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
I know i spend more time in this problem and i dont know where is the error here is my code again the cell value return null again where is the problem protected void grdSparepart_RowDeleting(object sender, GridViewDeleteEventArgs e) { //my problem here the string be null WHY??????????? :(( string spareid = grdSparepart.Rows[e.RowIndex].Cells[0].Text; :(( new DataAccess.Service().SparePart_Delete(spareid); DataSet ds = (DataSet)Session["dataset"]; ds.Tables[0].Rows[e.RowIndex].Delete(); grdSparepart.DataSource = ds; grdSparepart.DataBind(); lblmsg.Text = "delete ok "; lblmsg.Visible = true; }
Kareem Elhosseny
-
hi all, I just want to retrieve the cell value from the gridview using the following code,but it returns nothing null plz help me protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; //here to delete in data base //the problem in the next code this string (spareid)carry null string spareid = GridView1.Rows[index].Cells[0].ToString(); new DataAccess.Service().SparePart_Delete(spareid); //here to delete in dataset to reflect in gridview DataSet ds = (DataSet)Session["dataset"]; ds.Tables[0].Rows[index].Delete(); GridView1.DataSource = ds; GridView1.DataBind(); //here notification for delete lblmsg.Text = "delete ok "; lblmsg.Visible = true; } plz help me i dont know where is the error thanks in advice
Kareem Elhosseny
If you have DataKey attribute set of your GridView then you know: GridView1.SelectedIndex = e.RowIndex; In that case you know the GridView1.SelectedValue and that is your DataKey. With that value you can do a delete in the database and after that reload your DataSet ds and Databind() it to GridView1. Have Fun