请教一下!
       在DataGrid 控件的TemplateColumn模板中,加载了控件DropDownList,如:       <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 168px; POSITION: absolute; TOP: 72px"runat="server" AutoGenerateColumns="False">
     <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Height="40px"  ForeColor="Black" VerticalAlign="Middle"BackColor="#E1E1E1"></HeaderStyle>
     <Columns>
<asp:TemplateColumn HeaderText="类型" HeaderStyle-Width="50px">
     <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate> <asp:DropDownList Width="250px" id="Category1DropDownList"       Style="Width:31%;Font-Size:12px" runat="server">
<asp:ListItem Value="">==请选择==</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
        </Columns>
</asp:datagrid>
在*.cs文件中定义了
    ListItem listitem;
for(int i=1;i<4;i++)
{
listitem =new ListItem();
listitem.Value = i.ToString();
listitem.Text  ="请选择"+i.ToString();
                            }
        现在想把listitem绑定到Category1DropDownList中,该怎么做,谢谢大家!!!!!!!!

解决方案 »

  1.   

    instead of doing that, declare an variable in your codebehindprotected Hashtable ht = new Hashtable();....ht["请选择"] = "";for(int i=1;i<4;i++)
    {
       ht["请选择"+i.ToString()] = i.ToString();
    }
    <asp:DropDownList Width="250px" id="Category1DropDownList"       Style="Width:31%;Font-Size:12px" runat="server" DataSource="<%# ht%>" DataTextField="Key" DataValueField="Value">
    </asp:DropDownList>
    or if you insist, try to do the databinding in DataGrid's ItemDataBound event handler, seehttp://authors.aspalliance.com/das/dgcombo.aspx
      

  2.   

    在xx.aspx.cs中
       Hashtable ht=new HashTable();
       ht.Add("key","value");
       ht.Add("key","value");
       Category1DropDownList.DataSource=ht;
       Category1DropDownList.DataTextField="key";
       Category1DropDownList.DataValueField="value";