C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » JavaScript »

javascript for validating checkboxes checked are not,if checked confirmation for deleting


Posted Date: 31 Oct 2008      Posted By: A.raghavender      Member Level: Gold     Points: 1   Responses: 3



i have one delete button outside of gridview,in gridview if checkboxes selected,shwing confirmation for deleting the records using javascript




Responses

Author: Abhi    31 Oct 2008Member Level: DiamondRating: 3 out of 53 out of 53 out of 5     Points: 3

private void dgdetail_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

if(e.CommandName == "changestatus")
{
for(int i=0;i<dgdetail.Items.Count ;i++)
{
CheckBox Checkuser = (CheckBox) dgdetail.Items[i].FindControl("Checkuser");
if(Checkuser.Checked)
{
HtmlInputHidden hidPkid = (HtmlInputHidden) dgdetail.Items[i].FindControl("hidPkid");
int pkid=Convert.ToInt32(hidPkid.Value.ToString());
string updateuser="update LOGIN set USER_STATUS=1 where PK_USER_ID='"+pkid+"'";
connection ob=new connection();
ob.nonquery(updateuser);
RegisterStartupScript("hi","<script>alert('STATUS CHANGED SUCESSFULLY');</script>");
}
else
{
HtmlInputHidden hidPkid = (HtmlInputHidden) dgdetail.Items[i].FindControl("hidPkid");
int pkid=Convert.ToInt32(hidPkid.Value.ToString());
string updateuser="update LOGIN set USER_STATUS=0 where PK_USER_ID='"+pkid+"'";
connection ob=new connection();
ob.nonquery(updateuser);
RegisterStartupScript("hi","<script>alert('STATUS CHANGED SUCESSFULLY');</script>");

}
}



}

}


CODE WILL LIKE ABOVE.

here command name is for

<HeaderTemplate>
<asp:CheckBox ID="chkall" Runat="server" onclick="if(this.checked){checkall()}else{uncheckall()}"></asp:CheckBox>
<asp:Button runat="server" id="btnupdate" Text="CHANGE STATUS" style="WIDTH: 120px; COLOR: #ffffff; HEIGHT: 25px; BACKGROUND-COLOR: #00cccc"
CommandName="changestatus"></asp:Button>
</HeaderTemplate>

that no required as your requirement is concerned.

Thanks and Regards,
Abhay



Author: shekhar    31 Oct 2008Member Level: GoldRating:     Points: -20

function DeleteProducts()
{
? ?// Flag to indicate whether at least one product has been selected
?var hasSelected = false;

? ?// Get all checkboxes / products
? ?var products = document.getElementsByName( 'deleteproduct' );

? ?// Loop the checkboxes / products to check whether at least one product has been selected
? ?for( var n = 0; n < products.length; n++ )
? ?{
? ? ? ?if( products[n].checked )
? ? ? ? ? ?hasSelected = true;
? ?}
? ?
? ?if( hasSelected )
? ?{ ? // ...at least one product has been selected...
? ? ? ?if( confirm( "Are you sure you want to delete selected product(s)?" ))
? ? ? ?{ ? // ...ask for user confirmation whether to delete the selected product(s)
? ? ? ? ? ?for( var n = 0; n < products.length; n++ )
? ? ? ? ? ?{
? ? ? ? ? ? ? ?if( products[n].checked )
? ? ? ? ? ? ? ? ? ?alert( products[n].value );
? ? ? ? ? ?}
? ? ? ?}
? ?}
? ?else
? ?{ ? // ...no product has been selected...
? ? ? ?alert( "Please select at least one product to delete." );
? ?}
}



Author: shekhar    01 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

private void dgdetail_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

if(e.CommandName == "changestatus")
{
for(int i=0;i<dgdetail.Items.Count ;i++)
{
CheckBox Checkuser = (CheckBox) dgdetail.Items[i].FindControl("Checkuser");
if(Checkuser.Checked)
{
HtmlInputHidden hidPkid = (HtmlInputHidden) dgdetail.Items[i].FindControl("hidPkid");
int pkid=Convert.ToInt32(hidPkid.Value.ToString());
string updateuser="update LOGIN set USER_STATUS=1 where PK_USER_ID='"+pkid+"'";
connection ob=new connection();
ob.nonquery(updateuser);
RegisterStartupScript("hi","<script>alert('STATUS CHANGED SUCESSFULLY');</script>");
}
else
{
HtmlInputHidden hidPkid = (HtmlInputHidden) dgdetail.Items[i].FindControl("hidPkid");
int pkid=Convert.ToInt32(hidPkid.Value.ToString());
string updateuser="update LOGIN set USER_STATUS=0 where PK_USER_ID='"+pkid+"'";
connection ob=new connection();
ob.nonquery(updateuser);
RegisterStartupScript("hi","<script>alert('STATUS CHANGED SUCESSFULLY');</script>");

}
}



}

}

hope fully this will solve your problem
thank you



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : javascript doubt
Previous : Highlighting(chaning the color) the part of the text in textbox using javascript or vb.ne
Return to Discussion Forum
Post New Message
Category: JavaScript

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use