一取得数据表 i 行 j 列的值 //建立并打开数据库连接
OleDbConnection conn=new OleDbConnection();
connConnectionString=strConnectionString;//strConnectionString为数据库连接字符串
connOpen();
string sql=select * from NewsClass order by ClassId desc;
string x;
DataSet ds=new DataSet();
OleDbDataAdapter da=new OleDbDataAdapter(sqlconn);
daFill(dsNewsTable);
DataTable dt=dsTables[NewsTable];
x=dtRows[i][]ToString()//数据表i行j列的值
connclose();
二将数据读入DropDownList(
)DropDownList中添加数据
//建立并打开数据库连接
OleDbConnection conn=new OleDbConnection();
connConnectionString=strConnectionString;//strConnectionString为数据库连接字符串
connOpen();
string sql=select * from NewsClass order by ClassId desc;
//建立数据集
DataSet ds=new DataSet();
OleDbDataAdapter da=new OleDbDataAdapter(sqlconn);
daFill(dsNewsTable);
thisDropDownListDataSource=ds;
thisDropDownListDataTextField = ClassName;//Text值
thisDropDownListDataValueField = ClassID;//Value值
thisDropDownListDataBind();
connClose();
(
)选中DropDownList的某项
thisDropDownListItemsFindByValue(dr[ClassID]ToString()Trim())Selected=true;
//dr为DataRow
三分类编码检索出相应的分类名称并在DataGrid中显示
()ASPX中的代码(ClassID为分类编码)
<asp:TemplateColumn HeaderText=类 别>
<ItemTemplate>
<asp:Label id=lblClass runat=server
Text=<%# GetClassName(ConvertToInt(DataBinderEval(Container
DataItemClassID))) %>>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
()C#代码
/// /// 分类列根据数字返回文字
///
///
///
public string GetClassName(int ClassID)
{
OleDbConnection conn=new OleDbConnection();
connConnectionString=strConnectionString;
connOpen();
string sql=select * from NewsClass where ClassID=+ClassID;
DataSet ds=new DataSet();
OleDbDataAdapter da=new OleDbDataAdapter(sqlconn);
daFill(dsClassTable);
DataTable dt=dsTables[ClassTable];
string strClassName=dtRows[][ClassName]ToString();
connClose();
return strClassName;//返回 ClassID对应的ClassName
}