如何添加一个GridView的编辑内部级联下拉菜单?菜单、编辑、级联、GridView

2023-09-10 18:02:49 作者:且将桃花换酒钱

我有一个显示2列有父子关系相当标准的ASP.NET GridView控件。虽然关系存在于列A和B列的数据库,在GridView没有实现它。

I have a fairly standard ASP.NET GridView that displays 2 columns that have a parent child relationship. Although the relationship exists in the database between column A and column B, the GridView does not implement it.

我要做到以下几点: 当用户已选择要编辑的行,2下拉菜单变得可见。该DropDownB应自动填充基于DropDownA的值可用的选项。当DropDownA变化,DropDownB需要更新,以反映当前的选择。

I would like to do the following: When the user has elected to edit the row, 2 dropdown menus become visible. The DropDownB should automatically be populated with the available options based upon DropDownA's value. When DropDownA changes, DropDownB needs to be updated to reflect the current options.

目前可用列到网格:

 - ColumnAID
 - ColumnADescription
 - ColumnBID
 - ColumnBDescription

我一定可以做到这一点相同的功能电网之外,甚至可以有选择的行事件中显示一个模式弹出让我相应的编辑字段,但想保持这个包含到电网。

I can certainly accomplish this same functionality outside of the grid, could even have a selected row event display a modal popup allowing me to edit the fields accordingly, but would like to keep this contained to the grid.

推荐答案

这是你应该如何等等吧。

This is how you should so It.

1)GridView控件的页转到栏目主编。和列转换为要显示的DropDownList而不是文本框模板。

1.) Goto Column editor of the GridView. And convert the Column to Template which you want to display the DropDownList instead of the TextBox.

2。)转到GridView的智能标记,然后选择选项编辑模板。选择你的GridView列编辑器转换成模板列。

2.) Goto GridView SmartTag and select the Option to Edit Templates. Select the Column you converted into Template in GridView Column Editor.

3。)本专栏将有模板的所有意见。选择编辑视图。这已经有文本框在那里。

3.) This Column will have the Template for all the Views. Select the Edit view. This will already have TextBox there.

4)取出TxtBox,把一个DropDownList那里。您需要配置DropDownList的使用的ObjectDataSource或SqlDataSource的填充来自外部表中的数据。价值道具。将DropDownList应设定为ForeginTable的P.Key

4.) Remove the TxtBox and put a DropDownList there. You need to configure the DropDownList to populate the data from Foreign Table by using ObjectDataSource or SqlDataSource. The Value prop. of the DropDownList should be set to P.Key of the ForeginTable.

5)。现在,结合您的表中的SelectedValue外地来的Foregin关键。如果您使用绑定,将进行双向绑定为读/写,如果你使用eval它会执行单向结合阅读与设置的默认值。

5.) Now, bind the SelectedValue field to the Foregin Key in your table. If you use Bind it will perform Two-Way binding to Read/Write, If you use Eval it will perform OneWay binding to Read and set the default value only.

欲了解更多信息请访问此链接。

For more info visit this link.

LinkTxt: http://www.asp.net/学习/数据访问/教程-20-cs.aspx

感谢。

希望这会有所帮助。