388,817 Members | 2,642 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 388,817 IT Pros & Developers. It's quick & easy.

click event in gridview

maliksleo
100+
P: 115
hi all

i want to use a button in gridview and on the click event i would like to call a function for that i did the folowing
Expand|Select|Wrap|Line Numbers
  1. Sub ridgenerator(ByVal a As String)
  2.         Session("rid") = a
  3.         MsgBox("gg")
  4.         GridView2.DataBind()
  5.     End Sub
and on my markup its as below
Expand|Select|Wrap|Line Numbers
  1. <ItemTemplate>
  2. <table style="width: 100%; text-align: left">
  3. <tbody>
  4. <tr>
  5. <td style="width: 90%">
  6. <asp:LinkButton ID="LinkButton5" runat="server" Font-Underline="False" Text='<%# Eval "name") %>' OnClick='ridgenerator<%# Eval("f_id") %>' ></asp:LinkButton></td>
  7. </tr>
  8. </tbody>
  9. </table>
  10. </ItemTemplate>
but its not working whats wrong in it please do quick response.

maliksleo
Apr 13 '09 #1
Share this Question
Share on Google+
4 Replies


Frinavale
Expert Mod 5K+
P: 9,341
I'm not exactly sure what your problem is because you haven't stated it; but, MsgBox is not available in web applications.

You may want to consider placing a Label on the page and setting that Label's Text property to whatever it is you need to display:
Expand|Select|Wrap|Line Numbers
  1. Sub ridgenerator(ByVal a As String)
  2.         Session("rid") = a
  3.         messageLabel.Text = "gg"
  4.         GridView2.DataBind()
  5. End Sub
Apr 13 '09 #2

maliksleo
100+
P: 115
@Frinavale
i m sorry for not being so clear actually my function is not being called from the grid view on the click event of that linkbutton.
i just want you all to tell me the procedure by which i can call a function on a click event from the gridview.
And i m using web application there is no problem with the msgbox the only thing is
"HOW TO CALL THAT FUNCTION FROM GRIDVIEW USING LINKBUTTON?"
i did the folowing last time but didnt succeed
Expand|Select|Wrap|Line Numbers
  1. <asp:LinkButton ID="LinkButton5" runat="server" Font-Underline="False" Text='<%# Eval("name") %>' OnClientClick='<%# folderidgenerator(Eval("f_id")) %>' >
  2. </asp:LinkButton>
  3.  
any help?
Apr 14 '09 #3

Frinavale
Expert Mod 5K+
P: 9,341
I'm not sure if the LinkButton has been automatically generated for you (like the LinkButtons in the Header Row of the GridView used for sorting...or the edit/update/delete buttons).....

But, you should look into using the RowCommand Event. The RowCommand Event is raised whenever a control within the GridView raises an event.

Please note that you have to configure your GridView to use this event:
Expand|Select|Wrap|Line Numbers
  1.  <asp:GridView ID="GridView2" 
  2.                ...
  3.               OnRowCommand="ridgenerator"
  4.              runat="server">
  5.  
Apr 14 '09 #4

maliksleo
100+
P: 115
Thank you very much Frinavale it solved my problem once again thanks

maliksleo
Apr 15 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.