兄弟我刚学.请帮忙啊....String strsql = "select * from xhyx order by yxid desc";
SqlCommand cmd = new SqlCommand(strsql, mycon.conn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
将表中的数据绑到gridview上,其中的一个字段名为countryID是int类型.
其每个数字对应的是一个中文名.
如:
0 中国
1 英国
2 美国
3 香港
....前台页面的gridview中我用<%# DataBinder.Eval(Container.DataItem,"yxname")%>写法来显示内容.显示国家那一列我不想显示数字.我想显示数字对应的国家名称,应该怎么写啊?
SqlCommand cmd = new SqlCommand(strsql, mycon.conn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
将表中的数据绑到gridview上,其中的一个字段名为countryID是int类型.
其每个数字对应的是一个中文名.
如:
0 中国
1 英国
2 美国
3 香港
....前台页面的gridview中我用<%# DataBinder.Eval(Container.DataItem,"yxname")%>写法来显示内容.显示国家那一列我不想显示数字.我想显示数字对应的国家名称,应该怎么写啊?
你可以多表查询
select * from xhyx,GuoJia where xhyx.countryID=GuoJia.countryIDorder by yxid desc
帮定时
<%# DataBinder.Eval(Container.DataItem,"GuoJiaName")%>如果国家没有表而且国家相对很少
可以考虑绑定是替换
<Columns>
<asp:BoundField DataField="yxname" HeaderText="国家名字" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>如果是那样你不是麻烦吗?
如果真是那样你应该这样了protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.Trim() == "0")
{
e.Row.Cells[1].Text = "<font color=red>中国</font>";
}
if (e.Row.Cells[1].Text.Trim() == "1")
{
e.Row.Cells[1].Text = "<font color=red>英国</font>";//注意cell[i]里面的一定要对应好
}
}
}
case countryID
when 0 then '中国'
when 1 then '英国 '
when 2 then '美国'
when 3 then '香港'
end as country
from xhyx order by yxid desc