Wednesday, February 24, 2010

Gridveiw:Get all rows in one click

METHOD 1
===========================================
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{


try
{
Label5.Visible = true;
if (e.CommandName == "SET")
{
int IsFake = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{

int userid = int.Parse(GridView1.Rows[i].Cells[0].Text.ToString());
CheckBox chbTemp = GridView1.Rows[i].FindControl("chkBxSelect") as CheckBox;
if (chbTemp.Checked)
{
// Response.Write(GridView1.Rows[i].Cells[0].Text + "<BR>");
IsFake = 1;
}
UpdateTheDetails(userid, IsFake);
IsFake = 0;
}
Label5.Visible = true;
Label5.Text = "Success..Marked the Fake Members Successfully..";
Label5.BackColor = Color.Yellow;
Label5.ForeColor = Color.Green;
}
}
catch { }
}

================================================================
METHOD 2
=================================================================
protected void btnSubmit_Click(object sender, EventArgs e)
{

foreach (GridViewRow row in GridView1.Rows) //GridView1.PageSize * GridView1.PageCount
{
int IsFake = 0;
//Label lfilName = (Label)row.FindControl("lblfilename");
int userid = int.Parse(row.Cells[0].Text.ToString());

CheckBox chbTemp = (CheckBox)row.FindControl("chkBxSelect");
if (chbTemp.Checked)
{

IsFake = 1;
}
UpdateTheDetails(userid, IsFake);
IsFake = 0;
}
Label5.Visible = true;
Label5.Text = "Success..Marked the Fake Members Successfully..";
Label5.BackColor = Color.Yellow;
Label5.ForeColor = Color.Green;
}

No comments:

Post a Comment