将值从 TextBox 传递到 Telerik RadGrid
Pass values from TextBox to Telerik RadGrid
是否可以使用我从文本框中输入的值来填充 Radgrid 中的列?
这是我想从中获取值的文本框
<asp:TextBox ID="txtaddNum" TextMode="Number" Width="30px" runat="server" min="1" MaxLength="100" step="1" AutoPostBack="true"></asp:TextBox>
这是我的 radgrid,我要添加值的列是 "Commitment"
<telerik:RadGrid ID="grdAddGoals" AllowPaging="True" AllowSorting="true" PageSize="8"
runat="server" AutoGenerateColumns="False" ShowStatusBar="true" EnableLinqExpressions="false"
GridLines="None" CellPadding="0" HeaderStyle-Height="30" CellSpacing="0" EnableEmbeddedBaseStylesheet="false"
EnableEmbeddedSkins="false" Skin="BasicBlue" AllowFilteringByColumn="false" OnPreRender="grdAddGoals_PreRender"
OnItemCreated="grdAddGoals_ItemCreated">
<MasterTableView EnableNoRecordsTemplate="true">
<NoRecordsTemplate>
<asp:Label ID="lblNoMessage" runat="server" ForeColor="Red" Text="No Goals Detail Found"></asp:Label>
</NoRecordsTemplate>
<Columns>
<telerik:GridTemplateColumn HeaderText="" AllowFiltering="false" HeaderStyle-Width="30px">
<ItemTemplate>
<span style="background: url('App_Themes/BasicBlue/images/arrow_table.png') no-repeat scroll center center transparent;
width: 30px; margin-top: 5px;"> </span>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="Commitment" HeaderText="Commitment" AllowFiltering="false" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:TextBox ID="txtCommitment" runat="server" Width="109px"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="GoalNumber" DataField="GoalNumber" HeaderText="Goal" ItemStyle-HorizontalAlign="Center"
AllowFiltering="false" HeaderStyle-Width="50px" ShowSortIcon="true" SortAscImageUrl="App_Themes/BasicBlue/images/sortorderasc_arrow.png"
SortDescImageUrl="App_Themes/BasicBlue/images/sortorderdesc_arrow.png">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="True" />
<Scrolling AllowScroll="True" UseStaticHeaders="true" FrozenColumnsCount="2" ScrollHeight="200px"
SaveScrollPosition="True" />
</ClientSettings>
</telerik:RadGrid>
我试了所有方法都没有成功
我的理解是,当您在 "txtaddNum" 文本框中输入任何文本时,您希望在(所有)'txtCommitment' 文本框中显示相同的文本。如果我不正确,请告诉我。
请尝试使用以下代码片段。
ASPX.CS
protected void txtaddNum_TextChanged(object sender, EventArgs e)
{
foreach (GridDataItem dataItem in grdAddGoals.MasterTableView.Items)
{
TextBox txtQuantity = (TextBox)dataItem.FindControl("txtCommitment");
txtQuantity.Text = txtaddNum.Text;
}
}
ASPX
<asp:TextBox ID="txtaddNum" TextMode="Number" Width="30px" runat="server" min="1" MaxLength="100" step="1"
AutoPostBack="true" OnTextChanged="txtaddNum_TextChanged"></asp:TextBox>
如有任何疑问,请告诉我。
是否可以使用我从文本框中输入的值来填充 Radgrid 中的列?
这是我想从中获取值的文本框
<asp:TextBox ID="txtaddNum" TextMode="Number" Width="30px" runat="server" min="1" MaxLength="100" step="1" AutoPostBack="true"></asp:TextBox>
这是我的 radgrid,我要添加值的列是 "Commitment"
<telerik:RadGrid ID="grdAddGoals" AllowPaging="True" AllowSorting="true" PageSize="8"
runat="server" AutoGenerateColumns="False" ShowStatusBar="true" EnableLinqExpressions="false"
GridLines="None" CellPadding="0" HeaderStyle-Height="30" CellSpacing="0" EnableEmbeddedBaseStylesheet="false"
EnableEmbeddedSkins="false" Skin="BasicBlue" AllowFilteringByColumn="false" OnPreRender="grdAddGoals_PreRender"
OnItemCreated="grdAddGoals_ItemCreated">
<MasterTableView EnableNoRecordsTemplate="true">
<NoRecordsTemplate>
<asp:Label ID="lblNoMessage" runat="server" ForeColor="Red" Text="No Goals Detail Found"></asp:Label>
</NoRecordsTemplate>
<Columns>
<telerik:GridTemplateColumn HeaderText="" AllowFiltering="false" HeaderStyle-Width="30px">
<ItemTemplate>
<span style="background: url('App_Themes/BasicBlue/images/arrow_table.png') no-repeat scroll center center transparent;
width: 30px; margin-top: 5px;"> </span>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="Commitment" HeaderText="Commitment" AllowFiltering="false" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:TextBox ID="txtCommitment" runat="server" Width="109px"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="GoalNumber" DataField="GoalNumber" HeaderText="Goal" ItemStyle-HorizontalAlign="Center"
AllowFiltering="false" HeaderStyle-Width="50px" ShowSortIcon="true" SortAscImageUrl="App_Themes/BasicBlue/images/sortorderasc_arrow.png"
SortDescImageUrl="App_Themes/BasicBlue/images/sortorderdesc_arrow.png">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="True" />
<Scrolling AllowScroll="True" UseStaticHeaders="true" FrozenColumnsCount="2" ScrollHeight="200px"
SaveScrollPosition="True" />
</ClientSettings>
</telerik:RadGrid>
我试了所有方法都没有成功
我的理解是,当您在 "txtaddNum" 文本框中输入任何文本时,您希望在(所有)'txtCommitment' 文本框中显示相同的文本。如果我不正确,请告诉我。
请尝试使用以下代码片段。
ASPX.CS
protected void txtaddNum_TextChanged(object sender, EventArgs e)
{
foreach (GridDataItem dataItem in grdAddGoals.MasterTableView.Items)
{
TextBox txtQuantity = (TextBox)dataItem.FindControl("txtCommitment");
txtQuantity.Text = txtaddNum.Text;
}
}
ASPX
<asp:TextBox ID="txtaddNum" TextMode="Number" Width="30px" runat="server" min="1" MaxLength="100" step="1"
AutoPostBack="true" OnTextChanged="txtaddNum_TextChanged"></asp:TextBox>
如有任何疑问,请告诉我。