checkbox controls in datalist

hi... m having a problem with accessing checkbox in datalist, rather

Page 1 of 1

1 Replies - 11544 Views - Last Post: 05 November 2008 - 02:29 AM Rate Topic: -----

#1 shubh_3688   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-November 08

checkbox controls in datalist

Posted 03 November 2008 - 12:39 PM

my code is this

.aspx code
<div align="center">
		<table border="0" cellpadding="0" cellspacing="0" width="850px">
			<tr>
				<td align="left" style="padding-left: 20px">
					<br />					
						<asp:Button ID="btnApply" runat="server" Text="Apply For Selected Jobs" onclick="btnApply_Click" />
				</td>
			</tr>
			<tr>
				<td>
					<br />
					<asp:DataList ID="JobList" runat="server">
						<ItemTemplate>						
							<table border="0" cellpadding="0" cellspacing="0" width="850px" class="bottomfill"
								style="font-family: Verdana; font-size: 11px;">
								<tr>
									<td width="5px">
										<asp:CheckBox ID="apply" runat="server" />
									</td>
									<td align="left" style="color: Blue">
										<asp:Label ID="lblDesignation" runat="server" Text='<%#Eval(DataItem, "DesignationLevel") %>'></asp:Label>
										  -  
										<asp:Label ID="lblBasicKeySkills" runat="server" Text='<%#Eval("BasicKeySkills") %>'></asp:Label>
									</td>
									<td align="right" style="font-size: 9px; color: Gray">
										Posted Date :
										<asp:Label ID="lblPostedDate" runat="server" Text='<%#Eval("JobPostedDate") %>'></asp:Label>
									</td>
								</tr>
								<tr>
									<td>
									</td>
									<td colspan="2" align="left">
										<asp:Label ID="lblEmployerName" runat="server" Text='<%#Eval("EmployerName") %>'></asp:Label>
									</td>
								</tr>
								<tr>
									<td>
									</td>
									<td colspan="2" align="left">
										<asp:Label ID="lblCity" runat="server" Text='<%#Eval("CityName") %>'></asp:Label>
										(<asp:Label ID="lblState" runat="server" Text='<%#Eval("StateName") %>'></asp:Label>)
									</td>
								</tr>
								<tr>
									<td>
									</td>
									<td colspan="2" align="left">
										<asp:Label ID="lblQuality" runat="server" Text='<%#Eval("Quality") %>'></asp:Label>
										  ,  
										<asp:Label ID="lblExperience" runat="server" Text='<%#Eval("Experience") %>'></asp:Label>
									</td>
								</tr>
							</table>
							<hr style="border-style: dotted;" />
						</ItemTemplate>
					</asp:DataList>
				</td>
			</tr>
		</table>
	</div>



.aspx.cs code

 protected void Page_Load(object sender, EventArgs e)
	{
		string keyskills, functionalarea, industry;
		keyskills = Convert.ToString(Session["keyskills"]);
		functionalarea = Convert.ToString(Session["functionalarea"]);
		industry = Convert.ToString(Session["industry"]);
		SqlDataAdapter DaJob = new SqlDataAdapter("sql query",_connectio);
		DataTable dt = new DataTable();
		DaJob.Fill(dt);
		JobList.DataSource = dt;		
		JobList.DataBind();
  
	}

	protected void btnApply_Click(object sender, EventArgs e)
	{
		string isChecked;
		for (int i = 0; i < JobList.Items.Count; i++)
		{
			isChecked = ((CheckBox)JobList.Items[i].FindControl("apply")).Checked.ToString();
			Response.Write(isChecked);
		}
}



in Response.Write(isChecked);
it always shows False even if the check box is Checked


Is This A Good Question/Topic? 0
  • +

Replies To: checkbox controls in datalist

#2 Footsie   User is offline

  • D.I.C Regular
  • member icon

Reputation: 24
  • View blog
  • Posts: 370
  • Joined: 20-September 07

Re: checkbox controls in datalist

Posted 05 November 2008 - 02:29 AM

Quote

in Response.Write(isChecked);
it always shows False even if the check box is Checked


You need to check the property of the checkbox to determine whether it is checked or not, then set isChecked (which should be bool) to true or false:
bool isChecked = false;

if (myCheckBox.Checked == true)
{
  isChecked = true;
}



Please give a more detailed explanation of problems you are encountering along with errors etc so that others can help you out better if this doesn't answer your question.
Was This Post Helpful? 1

Page 1 of 1