【发布时间】:2020-10-28 06:38:17
【问题描述】:
我想将文本框值存储在隐藏字段中。并且需要在按钮单击时填充隐藏值,但问题是按钮和文本框都在 ASPxGridView 内。
ASPxGridView 是分层网格视图,即 (DetailRow)
代码
将值存储到隐藏字段中
function YourJavaScriptFunction() {
<%--$("#<%= hdn.ClientID %>").val($('<%# ((ASPxGridView)Container).FindControl("txtCustCode").ClientID %>').val());--%>
$("#hdn").val($("txtCustCode").val());
}
隐藏字段
<asp:HiddenField ID="hdn" runat="server" ClientIDMode="Static" />
网格视图
<dx:ASPxGridView ID="dgDepots" runat="server" ClientInstanceName="grid"
KeyFieldName="LocationCode" Width="100%" OnDataBinding="dgDepots_DataBinding"
OnRowDeleting="dgDepots_RowDeleting" OnRowInserting="dgDepots_RowInserting" OnRowUpdating="dgDepots_RowUpdating">
<Columns>
<dx:GridViewDataComboBoxColumn FieldName="LocationCode" PropertiesComboBox-ValueField="LocationCode" PropertiesComboBox-TextField="LocationName"
VisibleIndex="0">
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataComboBoxColumn FieldName="CostCenterCode" PropertiesComboBox-ValueField="CostCenterCode" PropertiesComboBox-TextField="CostCenterName"
VisibleIndex="1">
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataComboBoxColumn FieldName="GLCode" PropertiesComboBox-ValueField="GLAccountCode" PropertiesComboBox-TextField="GLAccountName"
VisibleIndex="2">
</dx:GridViewDataComboBoxColumn>
<dx:GridViewCommandColumn ShowNewButton="true" ShowEditButton="true" ShowDeleteButton="true" VisibleIndex="3">
</dx:GridViewCommandColumn>
</Columns>
<Templates>
<DetailRow>
<dx:ASPxGridView ID="dgCustomers" runat="server" KeyFieldName="CustomerCode"
OnBeforePerformDataSelect="dgCustomers_BeforePerformDataSelect" OnDataBinding="dgCustomers_DataBinding"
Width="100%" OnRowDeleting="dgCustomers_RowDeleting" OnRowInserting="dgCustomers_RowInserting"
OnRowUpdating="dgCustomers_RowUpdating">
<Columns>
<dx:GridViewDataTextColumn FieldName="CustomerCode" VisibleIndex="0">
<EditItemTemplate>
<asp:TextBox ID="txtCustCode" runat="server" Width="50px" />
</EditItemTemplate>
</dx:GridViewDataTextColumn>
<dx:GridViewDataColumn>
<EditItemTemplate>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClientClick="return YourJavaScriptFunction();" OnClick="btnSearch_Click" />
</EditItemTemplate>
</dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="PriceGroupCode" VisibleIndex="1">
<EditFormSettings Visible="True" />
</dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="ChannelCode" VisibleIndex="2">
</dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="SubChannelCode" VisibleIndex="3">
</dx:GridViewDataColumn>
<dx:GridViewCommandColumn ShowNewButton="true" ShowEditButton="true" ShowDeleteButton="true" VisibleIndex="4">
</dx:GridViewCommandColumn>
</Columns>
按钮点击后的代码隐藏
protected void btnSearch_Click(object sender, EventArgs e)
{
var ss = hdn.Value; **//Showing Null**
}
enter image description here 我哪里做错了?
【问题讨论】:
-
您好,
#附近有$("txtCustCode")..小姐。 -
@Swati 我按照你的建议进行了更改 $("#txtCustCode") 但没有更改