将虚拟项添加到DataGrid中的DropDownList [英] Adding dummy item to DropDownList in a DataGrid

查看:67
本文介绍了将虚拟项添加到DataGrid中的DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在DataGrid中有一个DropDownList,它是从

数据库中的记录填充的。


我想添加一个可能是字符串的值,例如Select a Company;对于

,如果您选择

第一项,则不会触发OnSelectedIndex事件的第一项。


有没有人知道一个简单的方法吗?


我使用以下代码来获取内部的下拉列表

a在数据网格内的单元格放置在里面我的PageLoad函数:


Dim list As DropDownList = New DropDownList()

Dim cell As TableCell = CType(list.Parent,TableCell)

Dim item As DataGridItem = CType(cell.Parent,DataGridItem)


Dim ddlCo As DropDownList = CType(item.FindControl(" ddlCo"),DropDownList)


ddlCo .Items.Add(" Select a Company")


我得到臭名昭着的对象引用未设置为实例

对象在昏暗的项目线上...


感谢任何回复...

glenn


Hi folks,

I have a DropDownList in a DataGrid that is populated from records in a
database.

I want to add a value that might be a string such as "Select a Company" for
the first item since an OnSelectedIndex event is not fired if you select the
first item.

Does anyone know of an easy way to do this?

I am using the following code to get at the the dropdownlist that is inside
a cell within the datagrid which is placed inside my PageLoad function:

Dim list As DropDownList = New DropDownList ( )
Dim cell As TableCell = CType(list.Parent, TableCell)
Dim item As DataGridItem = CType(cell.Parent, DataGridItem)

Dim ddlCo As DropDownList = CType(item.FindControl("ddlCo"), DropDownList)

ddlCo .Items.Add("Select a Company")

I am getting the infamous "object reference not set to an instance of an
object" on the Dim item line...

Appreciate any replies...
glenn


推荐答案

你的代码没有意义例如


Dim list As DropDownList = New DropDownList()


声明并启动一个名为list的DropdownList控件,然后


Dim cell As TableCell = CType(list.Parent,TableCell)


声明一个TableCell对象并将其设置为作为TableCell对象的单元控件的父控件

的值。但是在这一点上列表

对象,没有父控制。


你究竟想做什么?

" ;格伦"写道:
You code makes no sense for example

Dim list As DropDownList = New DropDownList ( )

declares and initiates a DropdownList control called list, then

Dim cell As TableCell = CType(list.Parent, TableCell)

declares a TableCell object and sets it to the value the the parent control
of the cell control cast as a TableCell object. But at this point the list
object, has no parent control.

What are you actually trying to do?
"glenn" wrote:
大家好,

我在DataGrid中有一个DropDownList,它是从
数据库中的记录中填充的。

我想添加一个可能是字符串的值,例如Select a Company;对于
第一项,因为如果您选择
第一项,则不会触发OnSelectedIndex事件。

是否有人知道一种简单的方法来执行此操作?
<我正在使用以下代码来获取位于我的PageLoad函数内的datagrid中的单元格内的下拉列表:

Dim list As DropDownList = New DropDownList ()
Dim cell As TableCell = CType(list.Parent,TableCell)
Dim item As DataGridItem = CType(cell.Parent,DataGridItem)

Dim ddlCo As DropDownList = CType (item.FindControl(" ddlCo"),DropDownList)

ddlCo .Items.Add(" Select a Company")

我得到了臭名昭着的对象引用未设置为
对象的实例昏暗的项目线...

感谢任何回复...
glenn
Hi folks,

I have a DropDownList in a DataGrid that is populated from records in a
database.

I want to add a value that might be a string such as "Select a Company" for
the first item since an OnSelectedIndex event is not fired if you select the
first item.

Does anyone know of an easy way to do this?

I am using the following code to get at the the dropdownlist that is inside
a cell within the datagrid which is placed inside my PageLoad function:

Dim list As DropDownList = New DropDownList ( )
Dim cell As TableCell = CType(list.Parent, TableCell)
Dim item As DataGridItem = CType(cell.Parent, DataGridItem)

Dim ddlCo As DropDownList = CType(item.FindControl("ddlCo"), DropDownList)

ddlCo .Items.Add("Select a Company")

I am getting the infamous "object reference not set to an instance of an
object" on the Dim item line...

Appreciate any replies...
glenn



我想在我的ddl中添加一个虚拟值,这样当我在ddl中选择第一个

实数值时,会触发一个OnSelectedIndex事件。价值

可能是例如选择公司。


我认为我提供的代码需要提供才能找到

控制在DataGrid中。如果ddl不在DataGrid中我可以

只需写下类似的东西:

Dim ddl as DropDownList = e.Item.Cells(2).FindControl(" ddlCompany" ;)

但由于它在DataGrid中,我需要额外的代码。


HTH。如果您知道更简单的方法,请告诉我。

谢谢,

glenn


" clickon"写道:
I am looking to add a dummy value to my ddl so that when I select the first
real value in the ddl, an OnSelectedIndex event will be fired. The value
might be for example, "Select a Company".

The code I presented I believe needs to be provided in order to find a
control that is inside a DataGrid. If the ddl was not in a DataGrid I could
simply write something like:
Dim ddl as DropDownList = e.Item.Cells(2).FindControl("ddlCompany")
but since it is inside the DataGrid, I needed the additonal code.

HTH. If you know of an easier way, please let me know.
Thanks,
glenn

"clickon" wrote:
你的代码没有意义,例如

Dim list As DropDownList = New DropDownList()

声明并启动一个DropdownList控件调用list,然后

Dim cell As TableCell = CType(list.Parent,TableCell)

声明一个TableCell对象并将其设置为父控件的值<将单元格控件转换为TableCell对象。但是在这一点上列表
对象,没有父控制。

你究竟想做什么?

" glenn"写道:
You code makes no sense for example

Dim list As DropDownList = New DropDownList ( )

declares and initiates a DropdownList control called list, then

Dim cell As TableCell = CType(list.Parent, TableCell)

declares a TableCell object and sets it to the value the the parent control
of the cell control cast as a TableCell object. But at this point the list
object, has no parent control.

What are you actually trying to do?
"glenn" wrote:
大家好,

我在DataGrid中有一个DropDownList,它是从
数据库中的记录中填充的。

我想添加一个可能是字符串的值,例如Select a Company;对于
第一项,因为如果您选择
第一项,则不会触发OnSelectedIndex事件。

是否有人知道一种简单的方法来执行此操作?
<我正在使用以下代码来获取位于我的PageLoad函数内的datagrid中的单元格内的下拉列表:

Dim list As DropDownList = New DropDownList ()
Dim cell As TableCell = CType(list.Parent,TableCell)
Dim item As DataGridItem = CType(cell.Parent,DataGridItem)

Dim ddlCo As DropDownList = CType (item.FindControl(" ddlCo"),DropDownList)

ddlCo .Items.Add(" Select a Company")

我得到了臭名昭着的对象引用未设置为
对象的实例在昏暗的项目线上......

感谢任何回复...
glenn
Hi folks,

I have a DropDownList in a DataGrid that is populated from records in a
database.

I want to add a value that might be a string such as "Select a Company" for
the first item since an OnSelectedIndex event is not fired if you select the
first item.

Does anyone know of an easy way to do this?

I am using the following code to get at the the dropdownlist that is inside
a cell within the datagrid which is placed inside my PageLoad function:

Dim list As DropDownList = New DropDownList ( )
Dim cell As TableCell = CType(list.Parent, TableCell)
Dim item As DataGridItem = CType(cell.Parent, DataGridItem)

Dim ddlCo As DropDownList = CType(item.FindControl("ddlCo"), DropDownList)

ddlCo .Items.Add("Select a Company")

I am getting the infamous "object reference not set to an instance of an
object" on the Dim item line...

Appreciate any replies...
glenn


只需将其添加到您的SQL


SELECT添加公司

UNION

SELECT CompanyName from Companies


" glenn" < GL *** @ discussions.microsoft.com>在留言中写道

news:68 ********************************** @ microsof t.com ...
Just add it to your SQL

SELECT "add a company"
UNION
SELECT CompanyName from Companies

"glenn" <gl***@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
我希望在我的ddl中添加一个虚拟值,这样当我在ddl中选择第一个
实际值时,将触发OnSelectedIndex事件。值
可能是例如选择公司。

我认为需要提供的代码是为了找到一个内部的控件。数据网格。如果ddl不在DataGrid中,我可以简单地写出如下内容:
Dim ddl as DropDownList = e.Item.Cells(2).FindControl(" ddlCompany")
但由于它在DataGrid中,我需要附加代码。

HTH。如果您知道更简单的方法,请告诉我。
谢谢,
glenn

clickon写道:
I am looking to add a dummy value to my ddl so that when I select the first
real value in the ddl, an OnSelectedIndex event will be fired. The value
might be for example, "Select a Company".

The code I presented I believe needs to be provided in order to find a
control that is inside a DataGrid. If the ddl was not in a DataGrid I
could
simply write something like:
Dim ddl as DropDownList = e.Item.Cells(2).FindControl("ddlCompany")
but since it is inside the DataGrid, I needed the additonal code.

HTH. If you know of an easier way, please let me know.
Thanks,
glenn

"clickon" wrote:
你的代码没有意义,例如

Dim list As DropDownList = New DropDownList()

声明并启动一个DropdownList控件调用list,然后

Dim cell As TableCell = CType(list.Parent,TableCell)

声明一个TableCell对象,并将其设置为父控制单元格控件转换为TableCell对象。但此时
列表
对象,没有父控件。

你究竟想做什么?

" glenn"写道:
You code makes no sense for example

Dim list As DropDownList = New DropDownList ( )

declares and initiates a DropdownList control called list, then

Dim cell As TableCell = CType(list.Parent, TableCell)

declares a TableCell object and sets it to the value the the parent
control
of the cell control cast as a TableCell object. But at this point the
list
object, has no parent control.

What are you actually trying to do?
"glenn" wrote:
>嗨伙计们,
>
>我在DataGrid中有一个DropDownList,它是从
>中的记录填充的。数据库。
>
>我想添加一个可能是字符串的值,例如选择公司
>对于
>如果你没有触发OnSelectedIndex事件,那么第一项是
>选择
>第一项。
>
>有谁知道一个简单的方法吗?
>
>我使用以下代码来获取
>的下拉列表里面
>数据网格中的一个单元格放在我的PageLoad函数中:
>
> Dim list As DropDownList = New DropDownList()
> Dim cell As TableCell = CType(list.Parent,TableCell)
> Dim item As DataGridItem = CType(cell.Parent,DataGridItem)
>
> Dim ddlCo As DropDownList = CType(item.FindControl(" ddlCo"),
> DropDownList)
>
> ddlCo .Items.Add(" Select a Company)
>
>我得到臭名昭着的对象引用未设置为
>的实例
>对象"在昏暗的项目行...
>
>感谢任何回复...
> glenn
>
>
>
>
> Hi folks,
>
> I have a DropDownList in a DataGrid that is populated from records in a
> database.
>
> I want to add a value that might be a string such as "Select a Company"
> for
> the first item since an OnSelectedIndex event is not fired if you
> select the
> first item.
>
> Does anyone know of an easy way to do this?
>
> I am using the following code to get at the the dropdownlist that is
> inside
> a cell within the datagrid which is placed inside my PageLoad function:
>
> Dim list As DropDownList = New DropDownList ( )
> Dim cell As TableCell = CType(list.Parent, TableCell)
> Dim item As DataGridItem = CType(cell.Parent, DataGridItem)
>
> Dim ddlCo As DropDownList = CType(item.FindControl("ddlCo"),
> DropDownList)
>
> ddlCo .Items.Add("Select a Company")
>
> I am getting the infamous "object reference not set to an instance of
> an
> object" on the Dim item line...
>
> Appreciate any replies...
> glenn
>
>
>
>



这篇关于将虚拟项添加到DataGrid中的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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