Here i have find the max value from DataTable using linq then i keep this value in ViewState. In the RowDataBound event of GridView i have compared the ViewState value with Cell value if its matched then i checked the RadioButton of that GridViewRow.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound"
HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="50" />
<asp:BoundField DataField="Value" HeaderText="Value" ItemStyle-Width="50" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" onclick="RadioCheck(this);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<hr />
<asp:Button ID="BShow" runat="server" Text="Show Data" />
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Value",typeof(int)) });
dt.Rows.Add(1, "aa", 30);
dt.Rows.Add(2, "bb", 80);
dt.Rows.Add(3, "cc", 60);
this.GridView1.DataSource = dt;
decimal max = dt.Select().Max(c => Convert.ToDecimal(c["Value"]));
ViewState["Max"] = max;
this.GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[2].Text == ViewState["Max"].ToString())
{
(e.Row.FindControl("RadioButton1") as RadioButton).Checked = true;
}
}
}
ScreenShot:
