Click here to Skip to main content
15,897,093 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
after bounding gridview with databse.
added added new column
FIELD TYPE : BUTTON FIELD
BUTTON TYPE :BUTTON
COMMAND NAME :SELECT

How to code on that Button_Click ??
Posted
Updated 8-May-13 8:05am
v3
Comments
Is this a DataGrid or GridView ?
praveen iThesisArt 8-May-13 14:01pm    
am sorry thats gridview ..
Ok, check my answer...
And if it is helpful, mark as answer and upvote.
praveen iThesisArt 8-May-13 22:21pm    
Can you tell me HOW can i pick that selected tuple any value (i.e column value) so that i can store that in session??
praveen iThesisArt 8-May-13 22:31pm    
onrowcommand="MyGridView_RowCommand" Where to place this ?

The GridView.RowCommand Event[^] will handle the button click.

You need to add one attribute onrowcommand="MyGridView_RowCommand" inside GridView MarkUp.

And define the Event in Code Behind as follows.
C#
void MyGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
    if(e.CommandName=="SELECT")
    {
        // Do whatever you want to do.
    }
}

Refer the MSDN link given above to know more and see the implementations.
 
Share this answer
 
here is my markup

C#
<asp:gridview id="GridView1" runat="server" allowpaging="True" xmlns:asp="#unknown">
                     AutoGenerateColumns="False" DataKeyNames="op" DataSourceID="SqlDataSource1"

                     style="z-index: 1; left: 276px;font-size:24px; top: 321px; position: absolute; height: 131px; width: 717px"
                     ForeColor="White" onrowcommand="GridView1_RowCommand">
                     <columns>
                         <asp:boundfield datafield="diarycontent" headertext="diarycontent">
                             SortExpression="diarycontent" />
                         <asp:boundfield datafield="diarypass" headertext="diarypass">
                             SortExpression="diarypass" />
                         <asp:boundfield datafield="diarydate" headertext="diarydate">
                             SortExpression="diarydate" />
                         <asp:boundfield datafield="opp" headertext="page number" sortexpression="opp" />
                         <asp:buttonfield buttontype="Button" commandname="Select">
                             HeaderText="view diary page" ShowHeader="True" Text="View Diary Page" />
                     </asp:buttonfield></asp:boundfield></asp:boundfield></asp:boundfield></columns>
                 </asp:gridview>


and cs code
C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {

       if (e.CommandName == "SELECT")
       {

           MessageBox.Show("hello");
       }
   }


and its not working.:(
 
Share this answer
 
Comments
The problem is in markup command name is "Select", but in code it is "SELECT". Make them same.
praveen iThesisArt 11-May-13 12:26pm    
Thanks a lot ..
Most welcome buddy... :)
praveen iThesisArt 13-May-13 1:27am    
Hey tadit one more question..
How can i pick particular value of a column on which button click is fired ..?
Take a look at the answer getting values of cells in rowcommand in gridview to know how to do it.

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