Null value from checkbox [Resolved]

Posted by Chaithragm under C# on 1/2/2013 | Points: 10 | Views : 2337 | Status : [Member] | Replies : 8
I am using check box to delete the selected files,here is code im using..
if i select the check box the selected file s deleting...
if i have not selected any checkbox and click the delete button it must show a message...(select file to delete) help me in doing this..


protected void delete_img_Click(object sender, ImageClickEventArgs e)
{


for (int i = 0; i < GridView1.Rows.Count; i++)
{

CheckBox cb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("ShowAddress");

if (cb != null)
{

if (cb.Checked)
{
string row_id = GridView1.DataKeys[i].Value.ToString();
delete_document(row_id);

}

}
}
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Selecte Files deleted successfully!!!'); window.location.href = 'Edit.aspx';", true);
}




Responses

Posted by: Ranjeet_8 on: 1/2/2013 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved

protected void delete_img_Click(object sender, ImageClickEventArgs e)
{
bool flag = false;
foreach (GridViewRow GvRow in GridView1.Rows)
{
CheckBox cb = (CheckBox)GvRow.FindControl("ShowAddress");
// Bind your Unique_ID with HiddenField inside Gridview
HiddenField hfRowID = (HiddenField)GvRow.FindControl("UniqueID");
if (cb != null)
{
if (cb.Checked)
{
string row_id = hfRowID.Value;
delete_document(row_id);
flag = true;
}
}
}
if (flag == true)
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Selected Files deleted successfully!!!'); window.location.href = 'Edit.aspx';", true);
else
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Error Msg goes here!!!'); ", true);
}


Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 1/2/2013 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this

protected void delete_img_Click(object sender, ImageClickEventArgs e)
{
foreach (GridViewRow GvRow in GridView1.Rows)
{
CheckBox cb = (CheckBox)GvRow.FindControl("ShowAddress");
// Bind your Unique_ID with HiddenField inside Gridview
HiddenField hfRowID = (HiddenField)GvRow.FindControl("UniqueID");
if (cb != null)
{
if (cb.Checked)
{
string row_id = hfRowID.Value;
delete_document(row_id);
}
}
}
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Selecte Files deleted successfully!!!'); window.location.href = 'Edit.aspx';", true);
}


Please Mark As Answer if this helps you

.

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 1/2/2013 [Member] Starter | Points: 25

Up
0
Down
where to display the message

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 1/2/2013 [Member] [MVP] Gold | Points: 25

Up
0
Down
after the end of foreach loop you can display d msg alert

Please Mark As Answer if this helps you

.

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 1/2/2013 [Member] Starter | Points: 25

Up
0
Down
that is sucess message displaying after foreach loop

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 1/2/2013 [Member] Starter | Points: 25

Up
0
Down
thank you ranjeet..

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/3/2013 [Member] Starter | Points: 25

Up
0
Down
hello will u please tell me wat is the use of of "delete_document"

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 1/4/2013 [Member] Starter | Points: 25

Up
0
Down
delete_document(row_id)

This method is for deleting a a file from the table.

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response