Hi selverca,
Please refer below sample.
HTML
<table>
<tr>
<td>UserName:</td>
<td><asp:TextBox ID="txtusername" runat="server" /></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnlogin" Text="Login" runat="server" OnClick="Login" /></td>
</tr>
</table>
<asp:Repeater ID="rptDetails" runat="server">
<HeaderTemplate>
<table>
<tr>
<td></td>
<td>Id</td>
<td>Proshektnummer</td>
<td>Prosjektnavn</td>
<td>prosjektbeskrivelse</td>
<td></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:CheckBox ID="chkBox" runat="server" /></td>
<td><asp:Label ID="lblId" Text='<%#Eval("Id") %>' runat="server" /></td>
<td><asp:Label ID="lblProshektnummer" Text='<%#Eval("Proshektnummer") %>' runat="server" /></td>
<td><asp:Label ID="lblProsjektnavn" Text='<%#Eval("Prosjektnavn") %>' runat="server" /></td>
<td><asp:Label ID="lblprosjektbeskrivelse" Text='<%#Eval("prosjektbeskrivelse") %>' runat="server" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Login(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] {
new DataColumn("Id"),
new DataColumn("Proshektnummer"),
new DataColumn("Prosjektnavn"),
new DataColumn("prosjektbeskrivelse")});
dt.Rows.Add("1", "123", "Testing1", "Database");
dt.Rows.Add("2", "456", "Testing2", "Database");
dt.Rows.Add("3", "789", "Testing3", "Database");
dt.Rows.Add("4", "555", "Testing4", "Database");
rptDetails.DataSource = dt;
rptDetails.DataBind();
string loginUser = txtusername.Text;
dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] {
new DataColumn("ID"),
new DataColumn("Prosjektnummer"),
new DataColumn("aktiv"),
new DataColumn("PI_bnava")});
dt.Rows.Add("37", "123", "False", "User1");
dt.Rows.Add("38", "789", "False", "User5");
dt.Rows.Add("39", "456", "False", "User1");
dt.Rows.Add("40", "123", "False", "User1");
DataRow[] dr = dt.Select("PI_bnava='" + loginUser + "'");
foreach (RepeaterItem item in rptDetails.Items)
{
Label pNo = item.FindControl("lblProshektnummer") as Label;
CheckBox isLogin = item.FindControl("chkBox") as CheckBox;
List<DataRow> result = dr.AsEnumerable().Where(x => x["Prosjektnummer"].ToString() == pNo.Text).ToList();
isLogin.Checked = result.Count > 0;
}
}
VB.Net
Protected Sub Login(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(3) {New DataColumn("Id"), New DataColumn("Proshektnummer"), New DataColumn("Prosjektnavn"), New DataColumn("prosjektbeskrivelse")})
dt.Rows.Add("1", "123", "Testing1", "Database")
dt.Rows.Add("2", "456", "Testing2", "Database")
dt.Rows.Add("3", "789", "Testing3", "Database")
dt.Rows.Add("4", "555", "Testing4", "Database")
rptDetails.DataSource = dt
rptDetails.DataBind()
Dim loginUser As String = txtusername.Text
dt = New DataTable()
dt.Columns.AddRange(New DataColumn(3) {New DataColumn("ID"), New DataColumn("Prosjektnummer"), New DataColumn("aktiv"), New DataColumn("PI_bnava")})
dt.Rows.Add("37", "123", "False", "User1")
dt.Rows.Add("38", "789", "False", "User5")
dt.Rows.Add("39", "456", "False", "User1")
dt.Rows.Add("40", "123", "False", "User1")
Dim dr As DataRow() = dt.Select("PI_bnava='" & loginUser & "'")
For Each item As RepeaterItem In rptDetails.Items
Dim pNo As Label = TryCast(item.FindControl("lblProshektnummer"), Label)
Dim isLogin As CheckBox = TryCast(item.FindControl("chkBox"), CheckBox)
Dim result As List(Of DataRow) = dr.AsEnumerable().Where(Function(x) x("Prosjektnummer").ToString() = pNo.Text).ToList()
isLogin.Checked = result.Count > 0
Next
End Sub
Screenshot