如何在asp.net中将下拉列表添加到Gridview中 [英] How to add dropdownlist into Gridview in asp.net
问题描述
我有一个网格控件,我想添加下拉列表框.下拉菜单的目的是在网格中显示页面,如果我选择 1 gridview page1 或 2 表示网格中的第二页等,当我要打印出来时,该下拉菜单不应该查看
I've a grid control, in that I want to add dropdownlist box. The pupose of the dropdown is to show the page in in the grid, If I select 1 the gridview page1 or 2 means 2nd page in the grid etc, that drop down should not view while I'm going to take print out
我当前的代码:
protected void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)
{
GridViewRow pagerRow = gvDetails.BottomPagerRow;
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
gvDetails.PageIndex = pageList.SelectedIndex;
}
推荐答案
要向网格单元添加下拉菜单,您应该使用 ItemTemplates
,尤其是编辑模式 ItemTemplate,请参阅此处获取完整示例: 演练:编辑时显示下拉列表在 GridView Web 服务器控件中
to add a drop down to a grid cell you should use ItemTemplates
and especially the edit mode ItemTemplate, see here for a full example: Walkthrough: Displaying a Drop-Down List While Editing in the GridView Web Server Control
无论如何,我不确定您对它的使用情况,如果您需要从一个页面移动到另一个页面,您应该使用页脚/分页控件,或者您可以在 GridView 外有一个下拉菜单,您可以在其中选择页面,然后您进行更改Grid 的 Current PageIndex 并再次调用 DataBind.
I am anyway not sure about your usage of it, if you need to move from one page to another you should use the Footer/Pager control or you can have a drop down outside the GridView where you select the page then you change the Current PageIndex of the Grid and call DataBind again.
这篇关于如何在asp.net中将下拉列表添加到Gridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!