<asp:GridView ID="GridView1" runat="server" EnableTheming="False" OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataTable dt = new DataTable("nameList");
dt.Columns.Add("name");
SPSite site = new SPSite("http://jack-7716f30e37:80");
using (SPWeb Web = site.OpenWeb())
{
SPList mylist = Web.Lists["MyList"];
SPQuery query = new SPQuery();
SPListItemCollection items = mylist.GetItems(query);
foreach (SPListItem item in items)
{
DataRow row = dt.NewRow();
row["name"] = item["Title"];
dt.Rows.Add(row);
}
}
((DropDownList)e.Row.FindControl("DropDownList1")).DataSource = dt;
((DropDownList)e.Row.FindControl("DropDownList1")).DataTextField = "name";
((DropDownList)e.Row.FindControl("DropDownList1")).DataBind();
}
}
No comments:
Post a Comment