English 中文(简体)
Gridview Bled DropDownList from Codethan
原标题:Gridview Binding DropDownList from code behind

我需要用核对箱子栏、 d栏和文字箱对电网进行约束。 就像默认模式一样。 请帮助我从编码背后对 com子项目进行约束。 Combo盒式值需要从网络服务中获取。 所有电网数据均由代码背后的约束。 用户可以改变电网数据。

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
        <Columns>
        <asp:TemplateField >
                <ItemTemplate >
                    <asp:CheckBox ID="CheckBox1" runat="server" Checked= "<%# Bind( select ) %>" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Roles">
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        SelectedValue= <%# Eval("Roles") %> >
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text="<%# Bind( Name ) %>"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

代码

 protected void Page_Load(object sender, EventArgs e)
{

    DataTable table = new DataTable();
    table.Columns.Add("select", typeof(bool));
    table.Columns.Add("Roles", typeof(string));
    table.Columns.Add("Name", typeof(string));
    table.Rows.Add(true, "Admin", "name1" );
    table.Rows.Add(true, "Admin", "name2");
    table.Rows.Add(true, "user", "name3");
    table.Rows.Add(false, "user", "name4");
    table.Rows.Add(false, "Admin", "name5");
    GridView1.DataSource = table;
    GridView1.DataBind();

}
最佳回答

你可以尝试这样的东西。

<asp:DropDownList ID="DropDownList1" runat="server" 
OnDataBound="DropDownList_OnDataBound"></asp:DropDownList>

以及

protected void DropDownList_OnDataBound(object sender, EventArgs e)

{
   DropDownList ddl = sender as DropDownList;
   if(ddl != null)
   {
        // call web service 以及 
        // populate ddl.Items
   }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签