我有一个基本的ASP.NET Gridview w / a ddlAction下拉列表
<asp:GridView ID="GridView1" CssClass="mgrid2"
runat="server" AutoGenerateColumns="False" ForeColor="White" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ClientName" HeaderText="ClientName" SortExpression="ClientName" />
<asp:BoundField DataField="ProjectID" HeaderText="ProjectID" SortExpression="ProjectID" />
<asp:BoundField DataField="ProjectName" HeaderText="ProjectName" SortExpression="ProjectName" />
<asp:BoundField DataField="Budget" HeaderText="Budget" ReadOnly="True" SortExpression="Budget" />
<asp:BoundField DataField="PercentComplete" HeaderText="PercentComplete" ReadOnly="True" SortExpression="PercentComplete" />
<asp:BoundField DataField="EarnedMH" HeaderText="EarnedMH" ReadOnly="True" SortExpression="EarnedMH" />
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlAction" CssClass="dropdownlist" runat="server" AutoPostBack="true" OnSelectedIndexChanged=""GridView1_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
它填充在rowdatabound
上 If e.Row.RowType = DataControlRowType.DataRow Then
Dim ddl = TryCast(e.Row.FindControl("ddlAction"), DropDownList)
If ddl IsNot Nothing Then
ddl.DataSource = New List(Of String)() From {
"Action",
"View",
"Edit",
"Archive"
}
ddl.DataBind()
End IF
我想让dropdownlist触发GridView1 selectedindexchanged事件,这样我就可以获得所选行的ProjectID,但我还想得到下拉列表中选定的值ddlAction
更新w / Answer
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
Dim ddl = DirectCast(sender, DropDownList)
Dim row As GridViewRow = CType(ddl.NamingContainer, GridViewRow)
通过这两项,您可以访问所需内容
答案 0 :(得分:0)
我暂时没有使用vb,但是你没有在事件方法中访问发件人?
var value = (sender as DropDownList).SelectedValue;