Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am using grid view in asp.net,and I want to fetch selected row values from the row using command augment and command name.
I am able to get one value which is bind to that link button but not all the values.

I am also trying to get it through row index.

Please help me.

Regards

Bilal
Posted
Updated 12-Aug-10 4:46am
v2
Comments
Dalek Dave 12-Aug-10 10:47am    
Edited for Readability and Syntax.

Hi,
Bila


Here is the solution to get the Values (Must defined in Gridview Datakeys) of the selected or clicked row.

VB
'It will find linkbutton in gridview container
Dim gvr As GridViewRow = CType(CType(e.CommandSource, LinkButton).NamingContainer, GridViewRow)
Dim intRow As Integer
'The container will return a selected row
intRow = gvr.RowIndex
'Assin keys of selected rows to datakey variable
Dim key As DataKey = gvPayment.DataKeys(intRow)
'Access the value (that you want) that will defined in Datakey
Dim tt As String = Convert.ToString(key("TransactionType"))



Please provide rating, if it would be helpfull to you :)

Thanks,
Imdadhusen
 
Share this answer
 
Comments
pronning300 16-Jul-10 14:37pm    
Reason for my vote of 5
thanks this was a good effect
Dalek Dave 12-Aug-10 10:47am    
Good Answer
In command argument , u can concatenate all the arguments which u need for the particular command . And then while getting the command name , split back the arguments..

For example:


CommandArgument='<%# Eval("mid")+"|"+ Eval("msgfrom")+"|"+Eval("subject") %>

Split;;
C#
if (e.CommandName == "Cname")
            {
                string delimStr = "|";
                char[] delimiter = delimStr.ToCharArray();
                string[] arguments = Convert.ToString(e.CommandArgument).Split(delimiter);


Thanks!
 
Share this answer
 
Comments
pronning300 12-Aug-10 9:32am    
how to get mid and msgfrom adn subject and assign to textbox ... please tell me asap
thanks Imdadhusen
i appreciate your effort .but i am coding in c# .
Also if you can provide me another solution...


thanks
 
Share this answer
 
C#
//It will find linkbutton in gridview container

{
	GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
	int intRow = 0;
	//The container will return a selected row
	intRow = gvr.RowIndex;
	//Assin keys of selected rows to datakey variable
	DataKey key = gvPayment.DataKeys[intRow];
	//Access the value (that you want) that will defined in Datakey
	string tt = Convert.ToString(key["TransactionType"]);
}
 
Share this answer
 
First get the reference of selected row and then from the gridview selected row get all the cell text values or controls binded value.

Ex:

GridViewRow gvr = GridView1.SelectedRow;

string name = gvr.Cells[2].Text;
......
 
Share this answer
 
Comments
pronning300 23-Jul-10 3:08am    
hi priya
where to put that code???

I have already tried this code in row command...

GridViewRow selectedRow = list_products.SelectedRow;
product objproduct = new product();
objproduct.userid = Convert.ToString(Session["id"]);
objproduct.productid = list_products.SelectedRow.Cells[2].Text;
objproduct.product_name = list_products.SelectedRow.Cells[3].Text;
objproduct.product_quantity = list_products.SelectedRow.Cells[4].Text;
objproduct.product_type = list_products.SelectedRow.Cells[5].Text;

error:Object reference not set to an instance of an object.
:rose::rose::rose::rose::rose::rose:
 
Share this answer
 

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