Hi itsme,
Refer below sample.
HTML
<asp:CheckBox ID="mon" Text="Monday" runat="server" /><br />
<asp:CheckBox ID="tues" Text="Tuesday" runat="server" /><br />
<asp:CheckBox ID="wed" Text="Wednesday" runat="server" /><br />
<asp:CheckBox ID="thrus" Text="Thrusday" runat="server" /><br />
<asp:CheckBox ID="fri" Text="Friday" runat="server" /><br />
<asp:CheckBox ID="sat" Text="Saturday" runat="server" /><br />
<asp:CheckBox ID="sun" Text="Sunday" runat="server" /><br />
<asp:GridView runat="server" AutoGenerateColumns="false" ID="gvDays">
<Columns>
<asp:TemplateField HeaderText="Days">
<ItemTemplate>
<asp:Label ID="lblweeks" runat="server" Text='<%#Eval("Days") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button Text="Edit" runat="server" OnClick="Edit" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Days");
dt.Rows.Add("Monday,Tuesday,Wednesday");
dt.Rows.Add("Monday,Tuesday,Wednesday,Thrusday");
dt.Rows.Add("Monday,Thrusday");
dt.Rows.Add("Tuesday,Sunday");
gvDays.DataSource = dt;
gvDays.DataBind();
}
}
protected void Edit(object sender, EventArgs e)
{
Button btn = sender as Button;
GridViewRow row = btn.NamingContainer as GridViewRow;
string weeks = (row.FindControl("lblweeks") as Label).Text;
string[] parts1 = weeks.Split(',');
mon.Checked = false;
tues.Checked = false;
wed.Checked = false;
thrus.Checked = false;
fri.Checked = false;
sat.Checked = false;
sun.Checked = false;
for (int i = 0; i < parts1.Length; i++)
{
if (parts1[i].ToUpper() == "MONDAY")
{
mon.Checked = true;
}
if (parts1[i].ToUpper() == "TUESDAY")
{
tues.Checked = true;
}
if (parts1[i].ToUpper() == "WEDNESDAY")
{
wed.Checked = true;
}
if (parts1[i].ToUpper() == "THRUSDAY")
{
thrus.Checked = true;
}
if (parts1[i].ToUpper() == "FRIDAY")
{
fri.Checked = true;
}
if (parts1[i].ToUpper() == "SATURDAY")
{
sat.Checked = true;
}
if (parts1[i].ToUpper() == "SUNDAY")
{
sun.Checked = true;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.Add("Days")
dt.Rows.Add("Monday,Tuesday,Wednesday")
dt.Rows.Add("Monday,Tuesday,Wednesday,Thrusday")
dt.Rows.Add("Monday,Thrusday")
dt.Rows.Add("Tuesday,Sunday")
gvDays.DataSource = dt
gvDays.DataBind()
End If
End Sub
Protected Sub Edit(ByVal sender As Object, ByVal e As EventArgs)
Dim btn As Button = TryCast(sender, Button)
Dim row As GridViewRow = TryCast(btn.NamingContainer, GridViewRow)
Dim weeks As String = (TryCast(row.FindControl("lblweeks"), Label)).Text
Dim parts1 As String() = weeks.Split(","c)
mon.Checked = False
tues.Checked = False
wed.Checked = False
thrus.Checked = False
fri.Checked = False
sat.Checked = False
sun.Checked = False
For i As Integer = 0 To parts1.Length - 1
If parts1(i).ToUpper() = "MONDAY" Then
mon.Checked = True
End If
If parts1(i).ToUpper() = "TUESDAY" Then
tues.Checked = True
End If
If parts1(i).ToUpper() = "WEDNESDAY" Then
wed.Checked = True
End If
If parts1(i).ToUpper() = "THRUSDAY" Then
thrus.Checked = True
End If
If parts1(i).ToUpper() = "FRIDAY" Then
fri.Checked = True
End If
If parts1(i).ToUpper() = "SATURDAY" Then
sat.Checked = True
End If
If parts1(i).ToUpper() = "SUNDAY" Then
sun.Checked = True
End If
Next
End Sub
Screenshot