我正在嘗試在dropdownlist的indexchange事件上爲hiddenfield賦值!其實問題是當我試圖更新我的記錄時,我無法找到隱藏字段的值!請給我解決方案或建議任何其他選項!謝謝 !在gridview中的boundfield中找不到值?
我的網格視圖是
<asp:TemplateField HeaderText="LocCode" SortExpression="LocCode">
<EditItemTemplate>
<ajax:UpdatePanel ID="upEditsLocation" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlLocation" runat="server"
DataSourceID="sdsLocation"
OnDataBound="ddlLocation_DataBound"
DataValueField="LocCode" AppendDataBoundItems="false"
DataTextField="LocCode"
AutoPostBack="true"
onselectedindexchanged="ddlLocation_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="sdsLocation" runat="server" ConnectionString="<%$ ConnectionStrings:ccConnString %>"
ProviderName="<%$ ConnectionStrings:CCConnString.ProviderName %>" SelectCommand="Select LocCode from Location">
</asp:SqlDataSource>
</ContentTemplate>
</ajax:UpdatePanel>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%# Bind("LocCode") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
和我indexchange事件是
protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
{
hdloc.Value = ddlLocation.SelectedItem.Text;
}
我的隱藏字段是
<asp:HiddenField ID="hdloc" runat="server" />
隱藏字段放置在哪裏?你的數據綁定控制之外? –
是的!但值分配給隱藏的領域,但我不能訪問它後面的代碼!當我嘗試訪問它時,我不知道實際的問題它給null! – Chintan
什麼不能訪問hdloc或ddlLocation? –