![string cell1 = GridView1.Rows[e.RowIndex].Cells[1].Text;获取不到值,第1张 string cell1 = GridView1.Rows[e.RowIndex].Cells[1].Text;获取不到值,第1张](/aiimages/string+cell1+%3D+GridView1.Rows%5Be.RowIndex%5D.Cells%5B1%5D.Text%3B%E8%8E%B7%E5%8F%96%E4%B8%8D%E5%88%B0%E5%80%BC.png)
首先你要确定,
GridView1Rows[eRowIndex]
是否存在,然后再确定
GridView1Rows[eRowIndex]Cells[1]
是否存在。这两个东西存在的话,理论上是可以拿到值的。
前台(如果在后台代码中用eCommandArgument取值的话前台代码就必须在按钮中设置CommandArgument的值,值为绑定的数据库字段<asp:TemplateFieldHeaderText=" *** 作"
<ItemTemplate
<asp:LinkButtonID="LinkButton1"runat="server
"CommandName="QianRu"
CommandArgument='<%#Eval("Id")%'签入</asp:LinkButton
<asp:LinkButtonID="LinkButton2"runat="server"CommandName="QianChu"签出</asp:LinkButton
</ItemTemplate
</asp:TemplateField后台在GridView里已经设置了LinkButton为事件处理按钮,将通过以下方法获取索引
protectedvoidgv_Company_RowCommand(objectsender,GridViewCommandEventArgse){
if(eCommandName=="QianRu")
{//取ID的值方法一
GridViewRowdrv=((GridViewRow)(((LinkButton)(eCommandSource))ParentParent));//此得出的值是表示那行被选中的索引值
infid=ConvertToInt32(GridView1DataKeys[drvRowIndex]Value);//此获取的值为GridView中绑定数据库中的主键值
//取ID的值方法二
GridViewRowdrv=((GridViewRow)(((LinkButton)(eCommandSource))ParentParent));//此得出的值是表示那行被选中的索引值
//此获取的值为GridView中绑定数据库中的主键值,取值方法是选中的行中的第一列的值,drvRowIndex取得是选中行的索引
intid=ConvertToInt32(GridView1Rows[drvRowIndex]Cells[0]Text);
//取ID的值方法三
//因为在客户端中就已经将LinkButton的CommandArgument与主键Id给绑定了所以在此可以直接用eCommandArgument得出主键ID的值
protected void imgBtnUp_Click(object sender, ImageClickEventArgs e)
{
ImageButton imageBtn = sender as ImageButton;
GridViewRow Row = imageBtnNamingContainer as GridViewRow;
int id = RowRowIndex;
}
参考上面的代码,其中id就是点击gridview中的BUTTON后怎么获得BUTTON所在行的索引值。
把按钮放在模板列里
在RowCommand事件中
GridViewRow gvrow = (GridViewRow)(((LinkButton)eCommandSource)NamingContainer);
// 获取到行索引 RowIndex
int index = gvrowRowIndex;
TextBox txtNo4 = (TextBox )grvViewRows[index]Cells[4]FindControl("txtNo4");
TextBox txtNo5 = (TextBox )grvViewRows[index]Cells[5]FindControl("txtNo5");
TextBox txtNo6= (TextBox )grvViewRows[index]Cells[6]FindControl("txtNo6");
这样写法就能获取对应的index行,即你点击按钮所在的行;对应列5、6、7列的textbox的值
txtNo4text
txtNo5text
txtNo6 text
读取excel中的数据,先加载好excel表,然后逐行逐列读取即可。
对于上面的行数不一样,其实行数是一样的,只是下面两行的C列数据为空而已,代码中加上判断即可。
示例代码如下:
for(int rowIndex=0;rowIndex<sheetgetPhysicalNumberOfRows();rowIndex++)
{
Row row = sheetgetRow(rowIndex);
if(row == null) continue;
for(int cellIndex=0;cellIndex<rowgetPhysicalNumberOfCells();cellIndex++)
{
Cell content = rowgetCell(cellIndex);
if(content== null) continue; //判断空
//对于内容进行 *** 作
}
}
有问题欢迎提问,,谢谢!
在GridView里已经设置了LinkButton为事件处理按钮,将通过以下方法获取索引
protected void gv_Company_RowCommand(object sender, GridViewCommandEventArgs e){if (eCommandName == "QianRu")
{
//取ID的值方法一
GridViewRow drv = ((GridViewRow)(((LinkButton)(eCommandSource))ParentParent)); //此得出的值是表示那行被选中的索引值
inf id=ConvertToInt32(GridView1DataKeys[drvRowIndex]Value); //此获取的值为GridView中绑定数据库中的主键值
//取ID的值方法二
GridViewRow drv = ((GridViewRow)(((LinkButton)(eCommandSource))ParentParent)); //此得出的值是表示那行被选中的索引值
//此获取的值为GridView中绑定数据库中的主键值,取值方法是选中的行中的第一列的值,drvRowIndex取得是选中行的索引
int id = ConvertToInt32(GridView1Rows[drvRowIndex]Cells[0]Text);
//取ID的值方法三
//因为在客户端中就已经将LinkButton的CommandArgument与主键Id给绑定了所以在此可以直接用eCommandArgument得出主键ID的值
int id = ConvertToInt32(eCommandArgumentToString());
}
}
以上就是关于string cell1 = GridView1.Rows[e.RowIndex].Cells[1].Text;获取不到值全部的内容,包括:string cell1 = GridView1.Rows[e.RowIndex].Cells[1].Text;获取不到值、GridView 动态绑定数据在页面浏览是如何获取选中行数据的ID号、asp.net gridview中如何获取选定行的索引值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)