View Full Version : access id of checkbox list items asp.net
sugeet_s
06-09-2006, 07:13 AM
hi
<asp:CheckBoxList ID="chkListInterest" runat="server" Style="z-index: 100; left: 424px;
position: absolute; top: 40px">
<asp:ListItem >Interest1</asp:ListItem>
<asp:ListItem >Interest2</asp:ListItem>
<asp:ListItem >Interest3</asp:ListItem>
<asp:ListItem >Interest4</asp:ListItem>
<asp:ListItem >Interest5</asp:ListItem>
</asp:CheckBoxList>
how to access id's of listitems in asp.net
thanks in advance
regards
sugeet
otaku149
06-09-2006, 01:50 PM
Hi sugeet_s,
You can get the ID using chkListInterest.ClientID & "_" & position(0 to ?):
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim s As String = "<b>Listitems ID:</b><br/>"
Dim i As Integer
For i = 0 To chkListInterest.Items.Count - 1
s = s & chkListInterest.ClientID & "_" & i.ToString()
s = s & "<br/>"
Next
lblMsg.Text = s
End Sub
Protected Sub btSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim s As String = "<b>Selected Listitems ID:</b><br/>"
Dim i As Integer
For i = 0 To chkListInterest.Items.Count - 1
If chkListInterest.Items(i).Selected Then
s = s & chkListInterest.ClientID & "_" & i.ToString()
s = s & "<br/>"
End If
Next
lblMsg.Text = s
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CheckBoxList Sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="chkListInterest" runat="server">
<asp:ListItem >Interest1</asp:ListItem>
<asp:ListItem >Interest2</asp:ListItem>
<asp:ListItem >Interest3</asp:ListItem>
<asp:ListItem >Interest4</asp:ListItem>
<asp:ListItem >Interest5</asp:ListItem>
</asp:CheckBoxList>
<p>
<asp:Button ID="btSubmit" runat="server" OnClick="btSubmit_Click" Text="Get the Selected Listitems ID!" />
</p>
<p>
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</p>
</div>
</form>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.