Y
Yan Wang
Hi!
Does anyone know how to get the text in textbox field which is in
HeaderTemplate of a DataGrid?
In the following code, I can not get text of "tbName". I typed something in
that box. I can get
tbName control but the text is empty.
Thanks a lot!
Yan
==================== asp ===============================================
<asp:datagrid Autogeneratecolumns="false" id="dgList" runat="server"
DataKeyField="ID">
<Columns>
<asp:TemplateColumn>
<ItemStyle></ItemStyle>
<ItemTemplate>
<asp:LinkButton Runat="server" CommandName="OnNameClicked">
<%# DataBinder.Eval(Container.DataItem, "NAME") %>
</asp:LinkButton>
</ItemTemplate>
<HeaderTemplate>
<table>
<tr>
<td>
<asp:LinkButton Runat="server" ID="btName"
OnCommand="OnNameSortClicked" CommandArgument="NAME">Name</asp:LinkButton>
<asp:Label Runat="server" ID="lbNameSort"></asp:Label>
</td>
<tr>
<td>
<asp:TextBox Runat="server" ID="tbName"
EnableViewState="True"></asp:TextBox>
</td>
</tr>
</table>
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
========================= sever =======================================
public void OnItemDataBound(object sender, DataGridItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Header) {
for (int i = 0; i < m_dgList.Columns.Count; ++i) {
Control aControl = null;
if (e.Item.Cells.HasControls()) {
aControl = e.Item.Cells.FindControl("tbName");
if (aControl != null) {
TextBox tbTemp = (TextBox)aControl; // I
reach here
if (tbTemp.Text != null && tbTemp.Text.Length > 0) {
tbTemp.Text = "Got it!";
//never reach here!!!!
}
}
}
}
}
}
Does anyone know how to get the text in textbox field which is in
HeaderTemplate of a DataGrid?
In the following code, I can not get text of "tbName". I typed something in
that box. I can get
tbName control but the text is empty.
Thanks a lot!
Yan
==================== asp ===============================================
<asp:datagrid Autogeneratecolumns="false" id="dgList" runat="server"
DataKeyField="ID">
<Columns>
<asp:TemplateColumn>
<ItemStyle></ItemStyle>
<ItemTemplate>
<asp:LinkButton Runat="server" CommandName="OnNameClicked">
<%# DataBinder.Eval(Container.DataItem, "NAME") %>
</asp:LinkButton>
</ItemTemplate>
<HeaderTemplate>
<table>
<tr>
<td>
<asp:LinkButton Runat="server" ID="btName"
OnCommand="OnNameSortClicked" CommandArgument="NAME">Name</asp:LinkButton>
<asp:Label Runat="server" ID="lbNameSort"></asp:Label>
</td>
<tr>
<td>
<asp:TextBox Runat="server" ID="tbName"
EnableViewState="True"></asp:TextBox>
</td>
</tr>
</table>
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
========================= sever =======================================
public void OnItemDataBound(object sender, DataGridItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Header) {
for (int i = 0; i < m_dgList.Columns.Count; ++i) {
Control aControl = null;
if (e.Item.Cells.HasControls()) {
aControl = e.Item.Cells.FindControl("tbName");
if (aControl != null) {
TextBox tbTemp = (TextBox)aControl; // I
reach here
if (tbTemp.Text != null && tbTemp.Text.Length > 0) {
tbTemp.Text = "Got it!";
//never reach here!!!!
}
}
}
}
}
}