Thank you RaviRanjankr, i was able to get age value, but now i am facing problem while sorting the age.below is the gridview code
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" EmptyDataText="Data Not Found !!!" Width="100%" DataSourceID="SqlDataSource1" PageSize="20" OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting" CssClass="gridviewheader">
<FooterStyle BackColor="#383838" Font-Bold="True" ForeColor="White" Font-Names="Arial,Helvetica,sans-serif" Font-Size="9px"/>
<RowStyle BackColor="#9f0000" ForeColor="white" Font-Names="Arial,Helvetica,sans-serif" Font-Size="9px" />
<AlternatingRowStyle BackColor="#EFF3FB" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="SLNO" HeaderText="SL #" SortExpression="SLNO" ItemStyle-ForeColor="#9f0000" ItemStyle-BackColor="#f7d9b0">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Age" SortExCan yopu
pression="Age">
<ItemStyle HorizontalAlign="center"></ItemStyle>
</asp:BoundField>
</Columns>
<PagerStyle BackColor="#e9b76b" ForeColor="#9f0000" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#e9b76b" Font-Bold="True" ForeColor="#9f0000" />
<HeaderStyle BackColor="#9f0000" Font-Bold="True" ForeColor="White" Font-Size="11px" Font-Names="Arial, Helvetcica, Sans-Serif" />
<EditRowStyle BackColor="#e9b76b" />
<AlternatingRowStyle BackColor="#e9b76b" ForeColor="#9f0000" />
</asp:GridView>
--------------------------------------------------------------------------------
below is the sorting code
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{ //Get GridViewRows
var rows = GridView1.Rows.Cast<GridViewRow>().Select(a => new
{
Number = Convert.ToInt32(GridView1.DataKeys[a.RowIndex].Value),
NumberText = ((Label)a.FindControl("Label1")).Text
});
//Get Sort Direction accordingly
SortDirection sortDirection = ViewState["SortOrder"] == null ? SortDirection.Descending :
(SortDirection)Enum.Parse(typeof(SortDirection), ViewState["SortOrder"].ToString()) == SortDirection.Ascending ?
SortDirection.Descending : SortDirection.Ascending;
ViewState["SortOrder"] = sortDirection;
if (sortDirection == SortDirection.Ascending)
rows = rows.OrderBy(a => a.NumberText);
else
rows = rows.OrderByDescending(a => a.NumberText);
GridView1.DataSource = rows.ToList();
GridView1.DataBind();
}
Can you please help me to sort the value
Thank you in advance