数据绑定下拉 [英] Databound Dropdown

查看:54
本文介绍了数据绑定下拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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");


这篇关于数据绑定下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆