【发布时间】:2013-02-14 04:54:54
【问题描述】:
您好,我正在尝试通过单击保存所有 gridview 值。
这是我尝试过的代码。
protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
{
// DAL and Other Code here
foreach (GridViewRow row in gvServicePort.Rows)
{
Label _lblOneID = gvServicePort.Rows[row.RowIndex].FindControl("lblOneID") as Label;
objserRtnDtls.TerminalID = Convert.ToInt16(_lblOneID .Text);
RadioButton _lblTwo = gvServicePort.Rows[row.RowIndex].FindControl("rdDirectPOL") as RadioButton;
if (_lblIsPOL.Checked == true)
objserRtnDtls.IsPOL = true;
else
objserRtnDtls.IsPOL = false;
int i = dalSPM.ServicePort_Update(objserRtnDtls, objSerRtn);
}
但是在这里,对于前两次迭代,我得到的返回值是 1,后来是 0,并且它没有保存在 DB 中
【问题讨论】:
-
尝试先检查是否是数据行:
row.RowType==DataControlRowType.DataRow -
您能否详细说明该代码
-
只需将
foreach循环的主体用if(row.RowType==DataControlRowType.DataRow)包裹起来
标签: asp.net gridview datagridview