1:datagrid
string strSomeId="";
for(int index=0;index<dataGrid.Items.Count;index++)
{
if(this.dataGrid.Items[index].ItemType==ListItemType.AlternatingItem || this.dataGrid.Items[index].ItemType==ListItemType.Item)
{
CheckBox check=(CheckBox)this.dataGrid.Items[index].FindControl("check");
if(check.Checked)
{
strSomeId+=this.dataGrid.DataKeys[index]+",";
}
}
else
{
continue;
}
}
return strSomeId.TrimEnd(',');
2:gridview
string pAllID = null;
foreach (GridViewRow gvRow in gvCopyright.Rows)
{
CheckBox check = (CheckBox)gvRow.FindControl("check");
if (check.Checked)
{
pAllID += gvCopyright.DataKeys[gvRow.RowIndex].Value.ToString() + ",";
}
else
{
continue;
}
}
return pAllID.TrimEnd(',');