Hi nedash,
I have created sample code which full-fill your requirement. You need to modify as per your requirement.
HTML
<asp:GridView ID="GrdMessage" runat="server" AutoGenerateColumns="false" Font-Size="14px"
OnRowDataBound="OnRowDataBound" PageSize="5" GridLines="Both" Width="338px" BorderColor="#808080"
BorderStyle="Solid" BorderWidth="1px" RowStyle-BorderColor="#808080" RowStyle-BorderStyle="Solid"
RowStyle-BorderWidth="1px" AlternatingRowStyle-BackColor="#C0C0C0" PagerStyle-HorizontalAlign="Center"
PagerStyle-VerticalAlign="Middle" ShowHeader="False" Font-Names="behtop_Yekan"
BackColor="#Fcfcfc" CssClass="gridGalary">
<Columns>
<asp:TemplateField ItemStyle-Width="0px">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("ID")%>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="54px" ItemStyle-VerticalAlign="Middle" ItemStyle-Height="38px">
<ItemTemplate>
<label id="Label1" runat="server" class="chlinkDoc1">
<input type="checkbox" id="ChBpriceL" runat="server" class="chlinkDoc1" /></label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="282px" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:Label ID="Lblname" runat="server" Text='<%#Eval("GroupName").ToString()%>' CssClass="lblQGK"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#eeeeee" />
<EmptyDataTemplate>
<table cellspacing="0" rules="all" border="1" id="GridView1" style="border-color: #919191;
border-width: 1px; border-style: Solid; font-family: yekan; font-size: 16px;
border-collapse: collapse;">
<tr style="background-color: #E0E0E0; border-color: #919191; border-width: 1px; border-style: Solid;">
<th scope="col" style="height: 18px; width: 517px">
گروه
</th>
</tr>
<tr>
<td colspan="7" align="center" style="height: 38px;" valign="middle">
تا کنون گروهی ثبت نشده
</td>
</tr>
</table>
</EmptyDataTemplate>
<RowStyle BorderColor="#919191" BorderWidth="1px" BorderStyle="Solid"></RowStyle>
</asp:GridView>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.PopulateData();
this.Group_First();
}
}
private void PopulateData()
{
DataTable dt = new DataTable("estate_info");
dt.Columns.Add("id");
dt.Columns.Add("group1");
dt.Columns.Add("group2");
dt.Columns.Add("group3");
dt.Columns.Add("group4");
dt.Rows.Add("1", "family", "", "", "job");
ViewState["Estate_Info"] = dt;
}
private void Group_First()
{
DataTable dt = new DataTable("Group_First");
dt.Columns.Add("id");
dt.Columns.Add("GroupName");
dt.Rows.Add("1", "family");
dt.Rows.Add("2", "school");
dt.Rows.Add("3", "friend");
dt.Rows.Add("4", "job");
GrdMessage.DataSource = dt;
GrdMessage.DataBind();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Name = (e.Row.FindControl("Lblname") as Label).Text;
DataTable dt = (DataTable)ViewState["Estate_Info"];
foreach (DataRow row in dt.Rows)
{
switch (Name.ToUpper())
{
case "FAMILY":
(e.Row.FindControl("ChBpriceL") as HtmlInputCheckBox).Checked = row["group1"].ToString() != "" ? true : false;
break;
case "SCHOOL":
(e.Row.FindControl("ChBpriceL") as HtmlInputCheckBox).Checked = row["group2"].ToString() != "" ? true : false;
break;
case "FRIEND":
(e.Row.FindControl("ChBpriceL") as HtmlInputCheckBox).Checked = row["group3"].ToString() != "" ? true : false;
break;
case "JOB":
(e.Row.FindControl("ChBpriceL") as HtmlInputCheckBox).Checked = row["group4"].ToString() != "" ? true : false;
break;
}
}
}
}
Vb.net
rotected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Me.PopulateData()
Me.Group_First()
End If
End Sub
Private Sub PopulateData()
Dim dt As New DataTable("estate_info")
dt.Columns.Add("id")
dt.Columns.Add("group1")
dt.Columns.Add("group2")
dt.Columns.Add("group3")
dt.Columns.Add("group4")
dt.Rows.Add("1", "family", "", "", "job")
ViewState("Estate_Info") = dt
End Sub
Private Sub Group_First()
Dim dt As New DataTable("Group_First")
dt.Columns.Add("id")
dt.Columns.Add("GroupName")
dt.Rows.Add("1", "family")
dt.Rows.Add("2", "school")
dt.Rows.Add("3", "friend")
dt.Rows.Add("4", "job")
GrdMessage.DataSource = dt
GrdMessage.DataBind()
End Sub
Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim Name As String = TryCast(e.Row.FindControl("Lblname"), Label).Text
Dim dt As DataTable = DirectCast(ViewState("Estate_Info"), DataTable)
For Each row As DataRow In dt.Rows
Select Case Name.ToUpper()
Case "FAMILY"
TryCast(e.Row.FindControl("ChBpriceL"), HtmlInputCheckBox).Checked = If(row("group1").ToString() <> "", True, False)
Exit Select
Case "SCHOOL"
TryCast(e.Row.FindControl("ChBpriceL"), HtmlInputCheckBox).Checked = If(row("group2").ToString() <> "", True, False)
Exit Select
Case "FRIEND"
TryCast(e.Row.FindControl("ChBpriceL"), HtmlInputCheckBox).Checked = If(row("group3").ToString() <> "", True, False)
Exit Select
Case "JOB"
TryCast(e.Row.FindControl("ChBpriceL"), HtmlInputCheckBox).Checked = If(row("group4").ToString() <> "", True, False)
Exit Select
End Select
Next
End If
End Sub
Screenshot