How to assign a text to Checkbox control and know which checkbox is selected

<asp:CheckBox id=’chkTips’ style=’Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 64px’ runat=’server’ Text=’Tips’></asp:CheckBox> <asp:CheckBox id=’chkTricks’ style=’Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 112px’ runat=’server’ Text=’Tricks’></asp:CheckBox> <asp:CheckBox id=’chkFaqs’ style=’Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 160px’ runat=’server’ Text=’Faqs’></asp:CheckBox> <asp:Button id=’btnSelect’ style=’Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 224px’ runat=’server’ Text=’Select’></asp:Button> VB.NET Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ’Put user code to initialize the page here If Not Page.IsPostBack Then End If End Sub Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click Dim ctl As Control Dim strchkSelected As String For Each ctl In Page.Controls(1).Controls If TypeOf ctl Is CheckBox Then if CType(ctl, CheckBox).Checked Then strchkSelected += CType(ctl, CheckBox).Text + ‘ ‘ End If End If Next Response.Write(strchkSelected) End Sub C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if (!Page.IsPostBack ) { } } private void btnSelect_Click(object sender, System.EventArgs e) { string strchkSelected=” ; foreach (Control ctl in Page.Controls[1].Controls ) { CheckBox chk = ctl as CheckBox ; if (chk!=null) { if (chk.Checked ) { strchkSelected += chk.Text + ‘ ‘ ; } } } Response.Write (strchkSelected); }

How to determine the Windows User from a Web form Application

Use the System.Security.Principal namespace. VB.NET dim wp as WindowsPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()) Response.Write(wp.Identity.Name) C# WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent()); Response.Write(wp.Identity.Name);

Which are the different ASP.NET authentication modes

ASP.NET supports the following Authentication Providers Windows : Is used in conjunction with IIS authentication. Authentication is performed by IIS in one of three ways: basic, digest, or Integrated Windows Authentication. When IIS authentication is complete, ASP.NET uses the authenticated identity to authorize access Forms : The user provides credentials and submits the form. Passport : Centralized authentication service provided by Microsoft that offers a single logon and core profile services for member sites. None : No Authentication provided. This is default Authentication mode In the web.config file, you can specify this setting: <authentication mode= ‘ [ Windows | Forms | Passport | None ] ‘> </authentication>

How to group the data in the DataList

<asp:DataList id=’DataList1′ runat=’server’ onItemDataBound=’ItemDB’> <HeaderTemplate > <table width=100%> </HeaderTemplate> <ItemTemplate> <tr><td> <asp:Label Runat=server text=<%#DataBinder.Eval(Container.DataITem, ‘Title’)%> ID=’lblTitle’> </asp:Label> <td><asp:Label Runat=server text=<%#DataBinder.Eval(Container.DataITem, ‘LastName’)%> ID=’lblLastName’> </asp:Label> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:DataList> VB.NET Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then BindTitle() End If End Sub ’Bind Data to DataList Populating the Dataset Sub BindTitle() Dim ds As New DataSet Dim sqlStmt As String = ‘SELECT * FROM Employees order by title’ Dim conString As String = ‘server=localhost;database=Northwind;uid=sa;pwd=;’ Dim myda As SqlDataAdapter = New SqlDataAdapter(sqlStmt, conString) myda.Fill(ds, ‘Table’) DataList1.DataSource = ds DataList1.DataBind() End Sub ’The ItemDataBound Event Protected Sub ItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then Dim strval As String = CType(e.Item.FindControl(‘lblTitle’), Label).Text Dim title As String = ViewState(‘title’) If title = strval Then CType(e.Item.FindControl(‘lblTitle’), Label).Text = ” e.Item.Visible = False Else title = strval ViewState(‘title’) = title CType(e.Item.FindControl(‘lblTitle’), Label).Text = title e.Item.Visible = True End If End If End Sub C# void Page_Load(object sender, EventArgs e) { if (!(Page.IsPostBack)) { BindTitle(); } } void BindTitle() { DataSet ds = new DataSet(); string sqlStmt = ‘SELECT * FROM Employees order by title’; string conString = ‘server=localhost;database=Northwind;uid=sa;pwd=;’; SqlDataAdapter myda = new SqlDataAdapter(sqlStmt, conString); myda.Fill(ds, ‘Table’); DataList1.DataSource = ds; DataList1.DataBind(); } protected void ItemDB(object sender, System.Web.UI.WebControls.DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item) { string strval = ((Label)(e.Item.FindControl(‘lblTitle’))).Text; string title = ViewState(‘title’); if (title == strval) { ((Label)(e.Item.FindControl(‘lblTitle’))).Text = ”; e.Item.Visible = false; } else { title = strval; ViewState(‘title’) = title; ((Label)(e.Item.FindControl(‘lblTitle’))).Text = title; e.Item.Visible = true; } } }