Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i get the cell value from specified cell in Gridview ? I have tried many methods but still not working.

When i click on stop button it will go to the rowcommand in the codebehind page and execute the code. But for executing the code i need the value in 5th cell of corresponding stop button row.

Here is the screenshot of my gridview:

Screenshot

One more question : How do i disable the stop button once clicked of the specific row ?

Please help me in this.

Thanks in Advance.
Posted
Updated 7-Jun-11 23:55pm
v5

As per ur question I undestood like this...

A GridView Contains Stop Button in all rows and Fixed coloums

Here is My solution

Go to Design of GridView

Inside ItemTemplete declare button with name btnStop
and commandArgument as '%# Eval("col5") %'

Declare all 5 coloums with eval inside ItemTemplate

So in GridView_Rowcommand Event U can get 5th col value easily
on clicking corresponding stop Button
 
Share this answer
 
v2
Comments
sharathu7 8-Jun-11 5:54am    
thanks and it worked perfectly... also screenshot updated... I need i more help how do i disable the stop button once clicked of each row.
HI

I could not open your screen shot.But follow my process

make autogenerate columns to false
Choose or enable select command in gridview properties

go to code behind of design view
and write the below code
<grid>
<columns>
<templatefield>
<itemtemplate>
5TH column data write here eg <#eval('columnname')>
</itemtemplate>
<edititem template="">
<asp:label id="lblgetdata' runat='server'>

</edititem></templatefield>
</columns>
</grid>

In RowCommand event
protected void gridview1_RowCommand(object sender, GridViewRowEventArgs e) 
{    
  Label l=(Label)e.FindControl('lblgetdata');
  string fifth_cellval=l.text;
}
 
Share this answer
 
v3
Comments
sharathu7 8-Jun-11 5:54am    
thank u for the help... this did not work... the solution 2 helped me...
Add command argument property to stop button as,
CommandArgument='<%#((Container)GridViewRow.RowIndex)%>'


Then you can get the row index by
e.commandargument returns the selected rows row index

gridview1.rows[Convert.toint32(e.rowcommand)].cells[1].text;will results the 1st cell value of corresponding row...
 
Share this answer
 
Comments
sharathu7 8-Jun-11 12:12pm    
Thanks... but its not working... it says.. "namespace name container could not be found".I tried importing namespace in aspx page but still no...
sharathu7 9-Jun-11 6:28am    
I tried it like this : ((GridViewRow) Container).RowIndex which i found here http://msdn.microsoft.com/en-us/library/bb907626.aspx
and its working... thanks for all ur help...
Here Is the Solution to Disable Stop Button

Just try this one even I dont that will work or not

--> Just pass two values inside CommandArgument
First One 5th Row Value and delimiter "-" and then RowIndex
C#
CommandArgument='<%# Eval("col5") + "-" + ((Container)GridViewRow.RowIndex)%>'

---------------
Now get whole value in RowCommand Event store it in string
Split the value based on delimiter " - "

U will get two values one 5th row value use it as before I said

and using RowIndex get the access of Button Control and Disable it.

Here is the code for that

string str = e.CommandArgument.ToString();

string[] prasad = str.Split('-');

string col5 = prasad[0];

int index = int.Parse( prasad[1] );

Button btnStop = (Button)GridView1.Rows[index].FindControl("btnStop"); 

btnStop.Enable = false;


Inform Me Once It Works Correctly. Thank You..
prasad22cm@hotmail.com
 
Share this answer
 
v2
Comments
sharathu7 8-Jun-11 12:05pm    
Thanks... but its not working... it says.. "namespace name container could not be found".I tried importing namespace in aspx page but still no...
sharathu7 9-Jun-11 6:28am    
I tried it like this : ((GridViewRow) Container).RowIndex which i found here http://msdn.microsoft.com/en-us/library/bb907626.aspx
and its working... thanks for all ur help...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900