Posted by Unknown on 5:05 AM
Labels:

Case: I have a gridview listing certain values and i have a checkbox as an item template
I want to build a string by appending checked values in the gridview..
eg:



we can make use of the string builder class for this.

using System.Text;

private string BuildStaffList(GridView grdVw, string chkName)
{
string StaffList = string.Empty;
StringBuilder str = new StringBuilder();
//gvStaff is the name of the GridView
for (int i = 0; i < gvStaff.Rows.Count; i++)
{
GridViewRow row = gvStaff.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("ChkSelect")).Checked;
//chkselect is the name of the checkbox

if (isChecked)
{
str = str.Append(gvStaff.Rows[i].Cells[1].Text.ToString() + "~");
}
}
StaffList = str.ToString();
return StaffList;

}
SUPPOSE I CHECK VALUES 1 & 2
Result:Sandhya Ramakrishnan~Shiju George

0 comments:

Post a Comment