Click here to Skip to main content
15,877,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello..

I want to get value of row command when user click a button inside gridview.

The gridview is in a modal popup, the modal popup is in tab container and the tab container is inside master page.

The problem is gridview_rowcommand not fired.

I've tried another method which calls button click event. But nothing happens too.

Here's the code for button click. The button click event is shared by 15 other buttons so that I didnt put 'handles button.click'

VB
 Protected Sub btn_Click(sender As Object, e As EventArgs)

ModalPopupExtender1.PopupControlID = "PanelShowMC"
        ModalPopupExtender1.TargetControlID = "PanelShowMC"
        ModalPopupExtender1.Show()

        ' MsgBox("FIRED!")
        Dim mainContent As ContentPlaceHolder = DirectCast(Me.Master.FindControl("MainContent"), ContentPlaceHolder)
        Dim tabCon As AjaxControlToolkit.TabContainer = DirectCast(mainContent.FindControl("TabContainer1"), AjaxControlToolkit.TabContainer)
        Dim tabPan As AjaxControlToolkit.TabPanel = DirectCast(tabCon.FindControl("TabPanel1"), AjaxControlToolkit.TabPanel)

        Dim gridv As GridView = DirectCast(tabPan.FindControl("gdShowArea"), GridView)

        Dim aaa As AsyncPostBackTrigger = New AsyncPostBackTrigger
        aaa.ControlID = gridv.UniqueID
        aaa.EventName = "gdShowArea_RowCommand"
        Dim btn As Button = sender
        MsgBox(btn.ID)

End Sub


HTML:

XML
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >
 <asp:ScriptManager ID="ScriptManager1" runat="server">
                          </asp:ScriptManager>
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
        Width ="1250px" Height="2000px"
                CssClass="Tab" >
                <cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="Machine Layout">

<HeaderTemplate> Machine Layout </HeaderTemplate>

<ContentTemplate>

<pre><cc1:ModalPopupExtender ID="panelShow_ModalPopupExtender" runat="server" 
        BackgroundCssClass="ModalPopupBG" OkControlID="btnClose" 
        PopupControlID="panelShow" TargetControlID="panelShow" 
        DynamicServicePath="" Enabled="True">
    </cc1:ModalPopupExtender>
    <asp:Panel ID="panelShow0" runat="server" BackColor="White" 
        BorderColor="#009900" BorderStyle="Solid" CssClass="ModalWindow" Height="600px" 
        Width="654px">
        <br />
        &nbsp;<asp:DropDownList ID="ddlArea" runat="server">
        </asp:DropDownList>
        <asp:Button ID="btnViewKIV" runat="server" CssClass="buttonMC" Text="View" />
        <br />
        <asp:GridView ID="gdShowArea" runat="server" AutoGenerateColumns="False" 
            BorderStyle="None" Height="500px" OnRowDataBound="gdShowArea_RowDataBound" 
            ShowHeader="False" Width="96px">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <center>
                            <asp:Button ID="btnC1" runat="server"                CausesValidation="False" 
CommandArgument="<%# Container.DataItemIndex + 1%>" 
CommandName="ViewC1" 
CssClass="btnmcdynamic" Font-Size="X-Small" Width="40px" />
                        </center>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <center>
                        <asp:Button ID="btnC2" runat="server" CommandName="ViewC1" 
                                CssClass="btnmcdynamic" Font-Size="X-Small" Width="40px" />
                        </center>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <br />
        <br />
        <center>
        </center>
    </asp:Panel>

</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>


</asp:Content>





gdShowArea_rowcommand:
  Private Sub gdShowArea_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gdShowArea.RowCommand

Dim i As Integer = CType(e.CommandArgument, Integer)
 Dim area As String = Me.ddlArea.SelectedItem.Text
        Dim col As String = btn.ID.Substring(3, 2)
        Dim row As String = "R" & i

        Dim loccode As String = String.Concat(area, col, row)
    End Sub 
Posted
Updated 10-Jan-13 13:00pm
v2
Comments
[no name] 10-Jan-13 5:05am    
please show me your source code
snamyna 10-Jan-13 19:00pm    
I've already updated the question. Tq
Member 9581488 10-Jan-13 22:08pm    
Try adding rowcommand in gridview tag.

<asp:GridView ID="gdShowArea" runat="server" AutoGenerateColumns="False"
BorderStyle="None" Height="500px" OnRowDataBound="gdShowArea_RowDataBound" OnRowCommand="gdShowArea_RowCommand"
ShowHeader="False" Width="96px">
snamyna 11-Jan-13 0:25am    
this will cause error. After removing onrowcommad, i just added "handles grid1.rowcommand, grid2.rowcommand, grid3.rowcommand" and the rowcommand event is fired. But another problem occurs where I cannot get the button ID inside item template of gridview. I've explained in comment below.

1 solution

hey try this..
add below Bold underline Line of code in your grid button.
and then try to fire it.
C#
<asp:button id="btn" runat="server" xmlns:asp="#unknown">
onClientClick = "$('btn').trigger('click');" ></asp:button>
 
Share this answer
 
v2
Comments
snamyna 11-Jan-13 0:25am    
Inside the gridview's item template, I got a dynamic button which i predetermine its id as 'btn1AC1'. On rowdatabound, I reset the button id according its row. Let say the button is on the 5th row of the gridview. The button ID is now '1AC1R5'. I want to get the exact button ID (1AC1R5), not the button general ID (btn1AC1). How to get that button ID so that I can set the button color according its ID. Tq
prashant patil 4987 11-Jan-13 0:59am    
when you create button dynamically then you just add this like below:
Button btn = new Button();
btn.onClientClick = "$('btn').trigger('click');";
when you add this. then automatically all button are have this.. just do it.
snamyna 11-Jan-13 3:19am    
I have a gridview with 2 columns with header text C1 and C2.Some buttons must be created in column C1 and others in C2.
How can I create those buttons according the columns dynamically?
prashant patil 4987 11-Jan-13 3:35am    
you have to take directly button click event instead of rowcommand event..
snamyna 11-Jan-13 4:20am    
i successfully created the button according columns. I already declare btn.onClientClick = "$('btn').trigger('click');"; on my new button. But when click on the button, it says null parameter value for $ sign. Should I declare the btn_Click event in vb or using javascript?

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