数据绑定下拉

问题描述:

DropDownList val1 = (DropDownList)Gridview1.Rows[intRow - 1].Cells[1].FindControl("txtItemCode");
TextBox val2 = (TextBox)Gridview1.Rows[intRow - 1].Cells[2].FindControl("txtDescription");





怎么了我得到的var1为null?
var2很好.





whats wrong here? i am getting var1 is null?
var2 is fine

可以用它从单元格中找到控件.

那里可能没有下拉菜单,或者您输入的名称可能与实际控件名称略有不同.

您始终可以通过以下方式检查单元是否具有控制权来继续操作.

It''s allright the way you''re using to find control from cell.

There may the chance of dropdown absense over there or the name you have written may be slightly different then the actual control name.

You could always move on by checking if the cell has control by following way.

if (grd.Rows[0].Cells[0].HasControls())
        {
        }


网格视图控件中的行和单元格从零开始索引.如果项目代码在第一列中,则需要在.Cells [0]而不是.Cells [1]处进行访问.如果您要获取的空值是我首先要验证的值.
The rows and cells in the grid view control are indexed as zero based. If the item code is in the first column, you need to access it at .Cells[0], not .Cells[1]. If you are getting null for the values that is the first thing I would validate.


我不会深入探讨该行,请尝试删除Cell属性.

I wouldn''t go that deep into the row, try removing the Cell property.

DropDownList val1 = (DropDownList)Gridview1.Rows[intRow - 1].FindControl("txtItemCode");
TextBox val2 = (TextBox)Gridview1.Rows[intRow - 1].FindControl("txtDescription");