问题描述:
c#中as的用法、意思?
as是干什么用的?具体语法是什么?
///
///
///
/// 要绑定的控件
/// 用于绑定的数据源
public static void Bind(WebControl wc,object dataSource)
{
if (wc is GridView)
{
GridView gv = wc as GridView;
gv.DataSource = dataSource;
gv.DataBind();
}
if (wc is DataList)
{
DataList dl = wc as DataList;
dl.DataSource = dataSource;
dl.DataBind();
}
if (wc is ListControl)
{
ListControl lc = wc as ListControl;
//lc.Items.Clear();
lc.DataSource = dataSource;
lc.DataBind();
if (dataSource is DbDataReader)
{
DbDataReader dr = dataSource as DbDataReader;
dr.Close();
}
}
}
as是干什么用的?具体语法是什么?
///
///
///
/// 要绑定的控件
/// 用于绑定的数据源
public static void Bind(WebControl wc,object dataSource)
{
if (wc is GridView)
{
GridView gv = wc as GridView;
gv.DataSource = dataSource;
gv.DataBind();
}
if (wc is DataList)
{
DataList dl = wc as DataList;
dl.DataSource = dataSource;
dl.DataBind();
}
if (wc is ListControl)
{
ListControl lc = wc as ListControl;
//lc.Items.Clear();
lc.DataSource = dataSource;
lc.DataBind();
if (dataSource is DbDataReader)
{
DbDataReader dr = dataSource as DbDataReader;
dr.Close();
}
}
}
问题解答:
我来补答展开全文阅读