最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在DataGrid里添加DropDownLit控件
时间:2022-06-30 10:12:03 编辑:袖梨 来源:一聚教程网
?
Using DropDownList control in DataGrid
By Eric Zheng
When I was developing a web application couple days ago, I found some interesting things about the datagrid, I want to share them with other vs.net programmers, so I wrote this article. This article will demonstrate how to use DropDownList control in datagrid.
The essential part of the DropDown.aspx file is the following:
In second line, we set the datasource of the dropdownlist control to a function 'GetCategory()', this function fetches the Category records from database and returns a datatable. In the last line, we set the SelectedIndex to a funciton 'GetCategoryID', this function takes the current Categoryname as its argument, and returns the locaiton(an integer) of the Categoryname, this enables the DorpDownList control to display the correct Categoryname for the current record.
The following is the C# code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Management
{
public class DropDown : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid ProductGrid;
protected DataTable _category;
//new a database class to get records, ProductDb is a public class
//containing several functions
protected ProductDb pdb=new ProductDb();
public DropDown()
{
Page.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
BindProduct();
}
}
private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
Using DropDownList control in DataGrid
By Eric Zheng
When I was developing a web application couple days ago, I found some interesting things about the datagrid, I want to share them with other vs.net programmers, so I wrote this article. This article will demonstrate how to use DropDownList control in datagrid.
The essential part of the DropDown.aspx file is the following:
In second line, we set the datasource of the dropdownlist control to a function 'GetCategory()', this function fetches the Category records from database and returns a datatable. In the last line, we set the SelectedIndex to a funciton 'GetCategoryID', this function takes the current Categoryname as its argument, and returns the locaiton(an integer) of the Categoryname, this enables the DorpDownList control to display the correct Categoryname for the current record.
The following is the C# code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Management
{
public class DropDown : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid ProductGrid;
protected DataTable _category;
//new a database class to get records, ProductDb is a public class
//containing several functions
protected ProductDb pdb=new ProductDb();
public DropDown()
{
Page.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
BindProduct();
}
}
private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22