2

I've read tens of posts about this issue and tried them all but with no luck, I'm not sure what am I missing this is gridview code:

<asp:GridView ID="recentJobsGridView" runat="server" CellPadding="4" ForeColor="#333333"
                            GridLines="None" Height="151px" Width="541px" Visible="False" AutoGenerateColumns="False"
                            PageSize="5" AllowPaging="True" OnPageIndexChanging="recentJobsGridView_PageIndexChanging"
                            DataKeyNames="orderItemId">
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <Columns>
                                <asp:TemplateField HeaderText="Order Date" Visible="true">
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("orderItemId") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Order Date">
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("orderDate") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="QTY">
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("QTY") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="ID">
                                    <ItemTemplate>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Length">
                                    <ItemTemplate>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("length") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="wall">
                                    <ItemTemplate>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("wall") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Paper Composition">
                                    <ItemTemplate>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("paperComposition") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="btAdd" runat="server" OnCommand="btAdd_Command"  Text="Add" 
                                        CommandArgument='<%# Container.DataItem %>' CommandName="Add"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <EditRowStyle BackColor="#999999" />
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#E9E7E2" />
                            <SortedAscendingHeaderStyle BackColor="#506C8C" />
                            <SortedDescendingCellStyle BackColor="#FFFDF8" />
                            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                            <SortedAscendingCellStyle BackColor="#E9E7E2" />
                            <SortedAscendingHeaderStyle BackColor="#506C8C" />
                            <SortedDescendingCellStyle BackColor="#FFFDF8" />
                            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                        </asp:GridView>

here is where I bind the grid view:

 protected void custGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (custGridView.SelectedDataKey != null)
        {
            selectCustomer = (int)custGridView.SelectedDataKey.Value;
            recentJobsGridView.Visible = true;
            recentJobsGridView.DataSource = ViewDataSource(selectCustomer);
            recentJobsGridView.DataBind();
        }

    }

and this is the code of the LinkButton:

 protected void btAdd_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "Add")
        {
            StatusLbl.Text = "Hellooooooo";
        }
    }

I removed everything I just want this message to be displayed but NOTHING is responding Help please...

3
  • 1
    If you dont have the !Ispostback at the page load, the event from the gridview does not fire. Commented Jun 19, 2013 at 18:47
  • Thanks but I have it already at the page_load Commented Jun 19, 2013 at 23:54
  • I had this issue. I was binding the data for the grid in the Page_PreRender, needed to do so in the page_load. Commented Mar 18, 2014 at 14:35

3 Answers 3

5

I see you are missing the onrowcommand in your gridview. Try this

asp:GridView ID="recentJobsGridView" runat="server" CellPadding="4" ForeColor="#333333"
                            GridLines="None" Height="151px" Width="541px" Visible="False" AutoGenerateColumns="False"
                            PageSize="5" AllowPaging="True" OnPageIndexChanging="recentJobsGridView_PageIndexChanging"
                            DataKeyNames="orderItemId"  onrowcommand="recentJobsGridView_RowCommand">

then add this to your codeFile

 protected void recentJobsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Add")) 
            {
              StatusLbl.Text = "Hellooooooo";
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

1

Try using the GridView's RowCommand event, which should fire on clicking the link button, with the command name/arg.

1 Comment

I think the problem is with binding the grid view when selecting a record from another gridview...what is the solution in this case??
0

Remove OnCommand="btAdd_Command", so LinkButton will be...

<asp:LinkButton ID="btAdd" runat="server" Text="Add" 
                CommandArgument='<%# Container.DataItem %>' 
                CommandName="Add">
</asp:LinkButton>

And add OnRowCommand="btAdd_Command" inside GridView.

<asp:GridView ID="recentJobsGridView" runat="server" CellPadding="4" 
              ForeColor="#333333" GridLines="None" Height="151px" Width="541px" 
              Visible="False" AutoGenerateColumns="False"
              PageSize="5" AllowPaging="True" 
              OnPageIndexChanging="recentJobsGridView_PageIndexChanging"
              DataKeyNames="orderItemId"
              OnRowCommand="btAdd_Command">

Now on Code Behind, modify the Button's definition like below...

protected void btAdd_Command(Object sender, GridViewCommandEventArgs e)
{
    // If multiple buttons are used in a GridView control, use the
    // CommandName property to determine which button was clicked.
    if (e.CommandName == "Add")
    {
        StatusLbl.Text = "Hellooooooo";
    }
}

Mark that you have to use GridViewCommandEventArgs, not CommandEventArgs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.