この例に従って、グリッドビュー編集モードで2つのカスケードドロップダウンリストを作成していますが、C#よりも作成しています:http: //mikepope.com/blog/DisplayBlog.aspx? permalink = 1708
しかし、私の@AttriFkは値を取得しません。このイベントでこれを設定するにはどうすればよいですか?
<asp:TemplateField HeaderText="Sub Attribute">
<EditItemTemplate>
<asp:DropDownList ID="ddlListSubAttributes" runat="server" AutoPostBack="True" DataSourceID="SqlDataSourceSubAttributes" DataTextField="Title" DataValueField="ID" />
<asp:SqlDataSource ID="SqlDataSourceSubAttributes" runat="server" ConnectionString="Data Source="//empty for this post" ProviderName="System.Data.SqlClient" SelectCommand="SELECT [ID],[Title],[AttriFk] FROM [LocalGTPDatabase].[dbo].[AttributeSubTypes] WHERE ([AttriFk] = @AttriFk)">
<SelectParameters>
<asp:Parameter Name="@AttriFk" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label66" runat="server" Text='<%# Bind("subAttribute") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
これは私の背後にあるコードの一部です:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
System.Data.DataRowView dv = (System.Data.DataRowView)e.Row.DataItem;
DropDownList ddlListAttributes = (DropDownList)(e.Row.FindControl("ddlListAttributes"));
String nest = Convert.ToString(dv["AttributeFk"]);
ddlListAttributes.SelectedValue = nest;
//Databind list of taskCode in dependent drop-down list, preselect value
DropDownList ddlListSubAttributes = (DropDownList)(e.Row.FindControl("ddlListSubAttributes"));
SqlDataSource dsc = (SqlDataSource)(e.Row.FindControl("SqlDataSourceSubAttributes"));
String testing = Convert.ToString(dv["AttributeFk"]);
//This is not working
dsc.SelectParameters["@AttriFk"].DefaultValue = Convert.ToString(dv["AttributeFk"]);
//Than I tried this but still it isn't working:
dsc.SelectParameters.Add("@AttriFk", Convert.ToString(dv["AttributeFk"]));
ddlListSubAttributes.DataBind();
ddlListSubAttributes.SelectedValue = Convert.ToString(dv["SubAttributeFk"]);
}
}