簡體   English   中英

帶DropDownList的EditItemTemplate-onselectedindexchanged

[英]EditItemTemplate with DropDownList - onselectedindexchanged

在我的EditTemplate中,我有一個DropDownList這樣的:

<EditItemTemplate>                      
    <asp:DropDownList ID="ddlFixture" runat="server"   AutoPostBack="True"   onselectedindexchanged="fixtureSelected"
           DataSourceID="FixtureDataSource"  DataTextField="WTag" DataValueField="WTag" AppendDataBoundItems="true" SelectedValue='<%#Bind("Fixure") %>'>
    </asp:DropDownList>                                                         
</EditItemTemplate>

當用戶從DropDownList中選擇一個項目時,我也想填充EditMode中的其他字段。

您會注意到,在onselectedindexchanged =“ fixtureSelected”上,我正在調用fixtureSelected。 我注意到了我面臨的一些問題:

protected void fixtureSelected(object sender, EventArgs e)
{
     // Below I am trying to get value of ddlFixture but it cannot recognize ddlFixture. GettingThe name 'ddlFixture' does not exist in the current context

     string fixtureId = ddlFixture.SelectedItem.Value;

    // I also need to update the text in EditMode but this will not work either. Get similar message as for ddlFixture 

    txtCampus.Text = "Campus1";             
}

您的問題是由於您試圖訪問的控件位於GridView的edititemtemplate中。

要進入dropdownlist實例,可以使用:

DropDownList ddlFixture = sender as DropDownList;

並在edititemtemplate中獲取其他控件,請使用:

ddlFixture.NamingContainer.FindControl("control_id")

例如:

TextBox txtCampus = ddlFixture.NamingContainer.FindControl("txtCampus") as TextBox;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM