如何获得该复选框被选中在GridView的价值? [英] How to get the value in the gridview which the checkbox is checked?
本文介绍了如何获得该复选框被选中在GridView的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有其中有一个复选框列网格视图...
Hi i have a grid view which has a checkbox column...
当过用户检查和clikcs按钮
这是我的网格的外观
when ever the user checks and clikcs on the button this is how my grid Looks
checkboxColumn|ID|CustomerNAme
--------------------------------------
1|asjd
2|asdfas
3|asdjka
assign(Button)
当用户签我要得到电网和stoer只有ID值到数据库中所需的行
When user checks the required rows i want to get only ID value of grid and stoer into database
protected void BtnAssignWork_Click(object sender, EventArgs e)
{
for (int i = 0; i < GrdCustomerData.RowsInViewState.Count; i++)
{
GridDataControlFieldCell cell = GrdCustomerData.RowsInViewState[i].Cells[0] as GridDataControlFieldCell;
CheckBox chk = cell.FindControl("Chkselect") as CheckBox;
if (chk.Checked == true)
{
var allIDs = (from item in GrdCustomerData.Rows.Cast<GridRow>()
let id = int.Parse(item.Cells[1].Text)
where chk.Checked
select id).ToList();
using (var myconn = new SqlConnection(connstring))
{
foreach (var id in allIDs)
{
using (var mycomm = new SqlCommand("SP_AssignedWork", myconn))
{
myconn.Open();
mycomm.CommandType = CommandType.StoredProcedure;
mycomm.Parameters.Add("@LoanID", SqlDbType.VarChar).Value = id;
mycomm.Parameters.Add("@EmpID", SqlDbType.VarChar).Value = DDLSelectEmployee.SelectedValue;
mycomm.ExecuteNonQuery();
myconn.Close();
}
}
}
}
任何一个可以帮我这个....
can any one help me with this....
推荐答案
任何方式我解决我的答案......
Any ways i solved my answer....
这里是code我希望它可能是有益的,在遇到一个....
here is the code i hope it may be helpfull to some one....
void grid1_RowDataBound(object sender, GridRowEventArgs e)
{
if (e.Row.RowType == GridRowType.DataRow && GrdCustomerData.RowsInViewState.Count > 0)
{
GridDataControlFieldCell cell = e.Row.Cells[0] as GridDataControlFieldCell;
CheckBox chk = cell.FindControl("Chkselect") as CheckBox;
GridDataControlFieldCell cellInViewState = GrdCustomerData.RowsInViewState[e.Row.RowIndex].Cells[0] as GridDataControlFieldCell;
CheckBox chkInViewState = cellInViewState.FindControl("Chkselect") as CheckBox;
if (cell.Value == chkInViewState.ToolTip)
{
chk.Checked = chkInViewState.Checked;
}
}
}
protected void BtnAssignWork_Click(object sender, EventArgs e)
{
string LoanIds = "";
for (int i = 0; i < GrdCustomerData.RowsInViewState.Count; i++)
{
GridDataControlFieldCell cell = GrdCustomerData.RowsInViewState[i].Cells[0] as GridDataControlFieldCell;
CheckBox chk = cell.FindControl("Chkselect") as CheckBox;
if (chk.Checked == true)
{
if (!string.IsNullOrEmpty(LoanIds))
LoanIds += "";
LoanIds = chk.ToolTip;
SqlConnection myconn = new SqlConnection(connstring);
SqlCommand mycomm = new SqlCommand("SP_AssignedWork", myconn);
myconn.Open();
mycomm.CommandType = CommandType.StoredProcedure;
mycomm.Parameters.Add("@LoanID", SqlDbType.VarChar).Value = LoanIds;
mycomm.Parameters.Add("@EmpID", SqlDbType.VarChar).Value = DDLSelectEmployee.SelectedValue;
mycomm.ExecuteNonQuery();
myconn.Close();
}
}
}
}
这篇关于如何获得该复选框被选中在GridView的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文