绑定: Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand DataGrid1.EditItemIndex = e.Item.ItemIndex Dim DstMoreDays As DealStateData With New DealStateSystem() DstMoreDays = .SelectMortDays(Date.Today) End With DataGrid1.DataSource = DstMoreDays DataGrid1.DataBind() '====================================================================== Dim count As Integer = 0 Dim ddl As DropDownList Dim TellTaskset As DealStateData Dim i, c As Integer c = DataGrid1.Items.Count If (c = 0) Then Exit Sub End If Dim logsetdata As Logdata With New logsystem() logsetdata = .BoundLogData("xxxxxxx", Session("department")) End With For i = 0 To (c - 1) '从列表依次选取每行Session("department") ddl = DataGrid1.Items(i).FindControl("dropdownlist1") If (Not (ddl Is Nothing)) Then '找到每行的下拉框 ddl.DataSource = logsetdata ddl.DataTextField = "name" ddl.DataBind() End If Next End Sub
Adding a DropDownList to an Editable DataGrid http://www.4guysfromrolla.com/webtech/050801-1.shtmlA DropDownList, EditItemTemplate, using Access, and HttpSessionState...Part 3 http://www.dotnetjunkies.com/Tutorial/ShowContent.aspx?cg=1646A7D2-A4CA-4CA2-B62D-C53903E9FBC5&forumID=4053
<asp:datagrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 14px; POSITION: absolute; TOP: 51px" runat="server" CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CC9966" Width="623px" Height="159px" AutoGenerateColumns="False" DataKeyField="taskcode" AllowPaging="True">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle Font-Size="13px" ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="13px" Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="taskcode" ReadOnly="True" HeaderText="任务编号"></asp:BoundColumn>
<asp:BoundColumn DataField="startdate" ReadOnly="True" HeaderText="分配日期" DataFormatString="{0:d}"></asp:BoundColumn>
<asp:BoundColumn DataField="enddate" HeaderText="处理期限" DataFormatString="{0:d}"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="选择新处理人">
<ItemTemplate>
<FONT face="宋体">
<asp:Label id="Label2" runat="server" text='<%# Container.dataitem("dealman") %>' Width="137px">
</asp:Label></FONT>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="DropDownList1" runat="server" Width="145px"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="保存" CancelText="取消" EditText="修改期限==变更代理人"></asp:EditCommandColumn>
<asp:ButtonColumn Text="删除任务" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:datagrid>
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand DataGrid1.EditItemIndex = e.Item.ItemIndex
Dim DstMoreDays As DealStateData
With New DealStateSystem() DstMoreDays = .SelectMortDays(Date.Today) End With DataGrid1.DataSource = DstMoreDays
DataGrid1.DataBind()
'======================================================================
Dim count As Integer = 0
Dim ddl As DropDownList
Dim TellTaskset As DealStateData
Dim i, c As Integer c = DataGrid1.Items.Count If (c = 0) Then Exit Sub End If Dim logsetdata As Logdata With New logsystem() logsetdata = .BoundLogData("xxxxxxx", Session("department")) End With
For i = 0 To (c - 1)
'从列表依次选取每行Session("department") ddl = DataGrid1.Items(i).FindControl("dropdownlist1")
If (Not (ddl Is Nothing)) Then '找到每行的下拉框 ddl.DataSource = logsetdata
ddl.DataTextField = "name"
ddl.DataBind() End If
Next End Sub
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server"> 1`121
protected DataTable GetProducts(int SupplierID){
SqlDataAdapter SqlDa = new SqlDataAdapter("SELECT ProductName, ProductID FROM Products WHERE SupplierID = @SupplierID", SqlCon);
SqlDa.SelectCommand.Parameters.Add(new SqlParameter("@SupplierID", SqlDbType.VarChar, 100));
SqlDa.SelectCommand.Parameters["@SupplierID"].Value = SupplierID;
DataSet ds = new DataSet();
SqlDa.Fill(ds, "ProductList");
return ds.Tables["ProductList"];
}
<columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" ItemStyle-VerticalAlign="top" />
<asp:BoundColumn HeaderText="ID" ReadOnly="True" DataField="SupplierID" ItemStyle-Wrap="false" ItemStyle-VerticalAlign="top" />
<asp:BoundColumn HeaderText="ID" ReadOnly="True" DataField="CompanyName" ItemStyle-Wrap="false" ItemStyle-VerticalAlign="top" />
<asp:TemplateColumn HeaderText="Products" >
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "ProductCount") %> Products
</ItemTemplate>
<EditItemTemplate>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="font-size:8" width="20%">
<b>CHANGE -</b>
</td>
<td>
<asp:DropDownList Runat="server" Id="edit_Product" DataSource='<%# GetProducts((int)DataBinder.Eval(Container.DataItem, "SupplierID")) %>' DataTextField="ProductName" DataValueField="ProductID" Width="200" />
</td>
</tr>
<tr>
<td style="font-size:8" width="20%">
<b>TO - </b>
</td>
<td>
<asp:TextBox id="NewProductName" runat="Server" Width="200" />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:TemplateColumn>
</columns>
</ASP:DataGrid>
http://www.4guysfromrolla.com/webtech/050801-1.shtmlA DropDownList, EditItemTemplate, using Access, and HttpSessionState...Part 3
http://www.dotnetjunkies.com/Tutorial/ShowContent.aspx?cg=1646A7D2-A4CA-4CA2-B62D-C53903E9FBC5&forumID=4053
CType(MyDataGrid.Items("循环变量1").Cells(循环变量2).Controls(0), dropdownlist)
http://218.84.107.5/g.aspx
http://218.84.107.5/g.aspx
<asp:DropDownList ID="Dropdownlist_usr_kind" Runat="server" Enabled="True" SelectedIndex='<%# DataBinder.Eval(Container.DataItem,"kind")%>'>
<asp:ListItem Value="1">领导</asp:ListItem>
<asp:ListItem Value="2">教师</asp:ListItem>
<asp:ListItem Value="3">领导、教师</asp:ListItem>
<asp:ListItem Value="4">学生</asp:ListItem>
<asp:ListItem Value="5">注册用户</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>