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

The following source i have used to show the data with group header. It is showing fine. But when i click on View link then grouped row rebind automatically. I tried to debug this binding in databound event. I couldnt catch it. What is the problem in my code to show the data in group wise.

ASP.NET
<asp:GridView ID="gvData" runat="server" Width="100%" AutoGenerateColumns="false"
    EmptyDataText="No record found" AllowSorting="false" AlternatingRowStyle-CssClass="alt"
    CssClass="myGrid" OnRowDataBound="gvData_RowDataBound" OnRowCommand="gvData_RowCommand">
    <Columns>
        <asp:BoundField HeaderText="Id" ItemStyle-HorizontalAlign="Left" DataField="RewardId"
            Visible="false" />
        <asp:BoundField HeaderText="Name" ItemStyle-HorizontalAlign="Left" DataField="AccountName" />
        <asp:BoundField HeaderText="Email" ItemStyle-HorizontalAlign="Left" DataField="Email" />
        <asp:BoundField HeaderText="Status" ItemStyle-HorizontalAlign="Left" DataField="StatusName" />
        <asp:BoundField HeaderText="Cash Back" ItemStyle-HorizontalAlign="Right" DataField="CashBack" />
        <asp:BoundField HeaderText="ATM Refund" ItemStyle-HorizontalAlign="Left" DataField="ATMRefund" />
        <asp:BoundField HeaderText="Send On" ItemStyle-HorizontalAlign="Left" DataField="SendOn" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkView" CommandName="View" CommandArgument='<%# Eval("RewardId") %>'
                    Text="View"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="Status" ItemStyle-HorizontalAlign="Left" DataField="Status"
            Visible="false" />
    </Columns>
</asp:GridView>


C#
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int rewardId = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "RewardId").ToString());
        if (rewardId < 0)
        {
            e.Row.Cells.Clear();
            TableCell cell = new TableCell();
            cell.Text = "Account Name : " + DataBinder.Eval(e.Row.DataItem, "AccountName").ToString();
            cell.ColumnSpan = 7;
            cell.CssClass = "GroupHeaderStyle";
            e.Row.Cells.Add(cell);
        }
    }
}

protected void gvData_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandArgument != null)
    {
        try
        {
            var strDataId = e.CommandArgument;
            if (strDataId != null && e.CommandName == "View")
            {
                int intID = Convert.ToInt32(strDataId);
                if (intID > 0)
                {
                    FillData(intID);
                }
            }

        }
        catch (Exception ex)
        {

        }
    }
}
Posted

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