我想有了下面两段就可以解决题目中的问题了,当然这个还没有涉及到模板列DropDownList数据绑定,但是我相信通过这个例子,再举一反三应该都可以解决的。这个方法应该算是比较简单的了吧,希望可以对不明白的朋友有所帮助。 :)
DataGrid模板列如下:
<%# DataBinder.Eval(Container,"DataItem.Credit")%>
SQL 语句如下:
select ID,Supp_Custom_NO,Name,rtrim(Phone) as Phone,rtrim(Fax) as Fax,Telation,Address,Zip,
case
when Credit='A' then '良好'
when Credit='B' then '较好'
when Credit='C' then '一般'
when Credit='D' then '较差'
end as Credit,
case
when Credit='A' then 0
when Credit='B' then 1
when Credit='C' then 2
when Credit='D' then 3
end as IndexCredit
from Supp_Custom_TB order by Supp_Custom_NO
DataGrid模板列如下:
<asp:TemplateColumn>
<HeaderTemplate>
信誉
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container,"DataItem.Credit")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="creditDlist" runat="server" Width="50" SelectedIndex='<%# DataBinder.Eval(Container, "DataItem.IndexCredit") %>'>
<asp:ListItem Value="良好">良好</asp:ListItem>
<asp:ListItem Value="较好">较好</asp:ListItem>
<asp:ListItem Value="一般">一般</asp:ListItem>
<asp:ListItem Value="较差">较差</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<HeaderTemplate>
信誉
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container,"DataItem.Credit")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="creditDlist" runat="server" Width="50" SelectedIndex='<%# DataBinder.Eval(Container, "DataItem.IndexCredit") %>'>
<asp:ListItem Value="良好">良好</asp:ListItem>
<asp:ListItem Value="较好">较好</asp:ListItem>
<asp:ListItem Value="一般">一般</asp:ListItem>
<asp:ListItem Value="较差">较差</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
select ID,Supp_Custom_NO,Name,rtrim(Phone) as Phone,rtrim(Fax) as Fax,Telation,Address,Zip,
case
when Credit='A' then '良好'
when Credit='B' then '较好'
when Credit='C' then '一般'
when Credit='D' then '较差'
end as Credit,
case
when Credit='A' then 0
when Credit='B' then 1
when Credit='C' then 2
when Credit='D' then 3
end as IndexCredit
from Supp_Custom_TB order by Supp_Custom_NO