Click here to Skip to main content
16,004,991 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I want to do code in row command event of gridview
and every time i want two value from database as command argument
How can i pass two values in command argument of link buuton inside the gridview
Posted
Comments
Amir Mahfoozi 15-Jan-12 7:20am    
Embed two values into an object which have an ID and put that ID in command parameters.

You can pass rowindex as command argument and retrieve that row in Row_Command.
C#
CommandArgument='<%# Container.DataItemIndex %>'


In your row_Command you can get the gridview row and then retrieve values in cells.

C#
protected void grdWhatever_RowCommand( object sender, GridViewCommandEventArgs e )
{
    int rowIndex = Convert.ToInt32( e.CommandArgument );
    GridViewRow row = grdWhatever.Rows[rowIndex];
}
 
Share this answer
 
Comments
NandaKumer 16-Jan-12 13:06pm    
good one
Hi, Use below:

CommandArgument='<%#Eval("Item_Id") +"|"+ (Container.ItemIndex+1)%>'
 
Share this answer
 
Use ASP Object DatasourceID, and bind the datasourceid to the gridview.
Place asp button and set the command argument as Insert.
 
Share this answer
 
Your linkbutton code
XML
<asp:TemplateField HeaderText="Receipt" SortExpression="Receipt">
       <ItemTemplate>
           <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Download" CommandArgument='<%# Eval("QuestionId") + "," + Eval("QuestionName")%>' Text='<%# Bind("QuestionName") %>'></asp:LinkButton>
    
      </ItemTemplate>
 </asp:TemplateField>


and then in your RowCommand you can use Split function to split the values by delimiter
C#
protected void gvTest_RowCommand(object sender, GridViewCommandEventArgs e)
 {
   if (e.CommandName == "Download")
   {
     string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' });
     string firstArgVal = commandArgs[0];
     string secondArgVal = commandArgs[1];
   }
 }
 
Share this answer
 
Comments
Member 11282695 3-Jan-15 2:01am    
how to create the dynamic add button when i click the add button to add the fields in one click....... for example like this site https://cvmkr.com/CV/new#3

Education field add delete button functionality

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