in your button click event, Iterate Repeater1.Items and then use FindControl to get Checkbox...and then write a if statement if checkbox is selected or not...finally if checkbox is selected insert it to Database...
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 66: {
Line 67: CheckBox chk = (CheckBox)i.FindControl("CheckBox");
Line 68: if (chk.Checked == true) Line 69: {
Line 70: genid= objmathod.genId();
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 66: {
Line 67: CheckBox chk = (CheckBox)i.FindControl("CheckBox");
Line 68: if (chk.Checked == true) Line 69: {
Line 70: genid= objmathod.genId();
exbond
Member
58 Points
144 Posts
how i can add the only checked values in db?
Apr 09, 2012 04:03 AM|LINK
hey!!
<asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table style="border:1px solid silver; border-collapse:collapse "> <tr> <td> ENROLLMENT NUMBER </td> <td> NAME </td> <td> EMAIL </td> <td> PASSWORD </td> <td> VERIFIED </td> </tr> </HeaderTemplate> <ItemTemplate> <tr><td><%databinder.eval(container.dataitem,"enroll")#%></td><td><%databinder.eval(container.dataitem,"name")#%></td><td><%databinder.eval(container.dataitem,"email")#%></td><td><%databinder.eval(container.dataitem,"password")#%></td><td> <asp:CheckBox ID="CheckBox1" runat="server" Checked="false" /></td></tr></ItemTemplate> <FooterTemplate> <tr><td colspan="5" align="center"> <asp:DataPager ID="DataPager1" runat="server" PageSize="3"> </asp:DataPager> </td></tr> <tr><td colspan="5" align="center"> <asp:Button ID="Button1" runat="server" Text="verify the checked" OnClick="Button1_Click" /></td></tr> </table> </FooterTemplate> </asp:Repeater>this is my aspx page for user verification...... now i want to add thee names to db who r verified or checked.
what i can do???
the repeater binds the data from a tabel Tbl_requestedusers ? i m not getting the code how to do this??
may be like this?but not working
if(checklist1.checked=true) ///this checklist1 is not appearing the scope also the asp:button is also not appearing
{ //insert query??
}
pradeepnt
Member
266 Points
154 Posts
Re: how i can add the only checked values in db?
Apr 09, 2012 11:23 AM|LINK
Hi....
write your insert query in:-
if(checkbox1.checked)
{
//your insert query
}
Pradeep Narayan
ramiramilu
All-Star
95503 Points
14106 Posts
Re: how i can add the only checked values in db?
Apr 09, 2012 11:39 AM|LINK
in your button click event, Iterate Repeater1.Items and then use FindControl to get Checkbox...and then write a if statement if checkbox is selected or not...finally if checkbox is selected insert it to Database...
Thanks,
JumpStart
priyankmtr
Contributor
2626 Points
526 Posts
Re: how i can add the only checked values in db?
Apr 09, 2012 11:51 AM|LINK
protected void btnApprove_Click(object sender, EventArgs e)
{
try
{
if (ddlStatus.SelectedIndex == 1)
{
string result = string.Empty;
{
CheckBox chkcheck = (CheckBox)
ri.FindControl("chksel");if (chkcheck.Checked)
{
TextBox txtcomment = (TextBox)grdList.Rows[i].FindControl("txtcomment");
Label lblRecId = (Label)grdList.Rows[i].FindControl("lblEmpid");
Int64 Recid = Convert.ToInt64(lblRecId.Text);
result = UpdateReviewComment(Recid, txtcomment.Text, Status.Active.GetHashCode().ToString());
if (result)
{
lblResult.Text="Updated Successfully";
}
}
}
if (result == Result.Success.ToString())
{
lblresult.Text = "Records approved successfully";
lblresult.Attributes.Add("style", "color:green;");
Bind();
}
}
}
catch (Exception ex)
{
}
}
(Mark as Answer If you find helpful)
narasappa
Participant
960 Points
458 Posts
Re: how i can add the only checked values in db?
Apr 09, 2012 12:07 PM|LINK
if(chkbox1.checked)
{
//ur code
} it wil return boolean value
ravi.jadiyannavar@gmail.com
Pls Mark This Post As Answer If it Helps U..
Thanku
exbond
Member
58 Points
144 Posts
Re: how i can add the only checked values in db?
Apr 09, 2012 01:31 PM|LINK
error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 66: { Line 67: CheckBox chk = (CheckBox)i.FindControl("CheckBox"); Line 68: if (chk.Checked == true) Line 69: { Line 70: genid= objmathod.genId();
protected void Button1_Click(object sender, EventArgs e) { string genid=string.Empty; foreach (RepeaterItem i in Repeater1.Items) { if (i.ItemType == ListItemType.Item) { CheckBox chk = (CheckBox)i.FindControl("CheckBox"); if (chk.Checked == true) { genid = objmathod.genId(); dcdc.modify_request(Convert.ToInt32(2), genid); } else { } } } }exbond
Member
58 Points
144 Posts
Re: how i can add the only checked values in db?
Apr 09, 2012 01:32 PM|LINK
error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 66: { Line 67: CheckBox chk = (CheckBox)i.FindControl("CheckBox"); Line 68: if (chk.Checked == true) Line 69: { Line 70: genid= objmathod.genId();
protected void Button1_Click(object sender, EventArgs e) { string genid=string.Empty; foreach (RepeaterItem i in Repeater1.Items) { if (i.ItemType == ListItemType.Item) { CheckBox chk = (CheckBox)i.FindControl("CheckBox"); if (chk.Checked == true) { genid = objmathod.genId(); dcdc.modify_request(Convert.ToInt32(2), genid); } else { } } } }