[.net]DataGrid中绑定DropDownList

[.net]DataGrid中绑定DropDownList

在DataGrid中加入DropDownList:
<asp:TemplateColumn HeaderText="au_lname">
         <itemtemplate>
     <asp:Label runat="server"
       Text='<%# DataBinder.Eval(Container.DataItem, "au_lname") %>'/>
         </itemtemplate>
         <edititemtemplate>
     <asp:DropDownList runat="server"
       DataSource='<%# GetDataTable1() %>'
       DataTextField="au_lname"
       id="au_lname" />
DropDownList绑定数据代码:
public DataTable GetDataTable1(){
String selectCmd = "select DISTINCT au_lname  from Authors";
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Integrated Security=SSPI");
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "au_lname");
DataTable dt = ds.Tables["au_lname"];
return dt;
     }

你可能感兴趣的:(datagrid)