Text box as part of the header row...

WellsCarrie

Well-known member
Joined
Jul 12, 2005
Messages
95
Location
Arkansas
Programming Experience
5-10
My requirements call for the user to beable to search the Name field on my grid view. The business owner wants the search box to be located in the Name column's header.
VB.NET:
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="bottom" ItemStyle-Font-Size="10px" ItemStyle-Font-Bold="true">
<HeaderTemplate>
   <asp:Label ID="lblHeaderText" runat="server" CssClass="label" Text="Name " />
   <asp:TextBox ID="txtSearchName"  CssClass="textbox" MaxLength="40" Width="60" Runat="Server" /> 
   <asp:ImageButton ID="btnSearch" runat="server" ImageUrl="images/SearchImage.JPG" ImageAlign="bottom" 
          AlternateText="SEARCH NAME" CommandName="SearchNames" CommandArgument='<%# Eval("txtSearchName.Text") %>' />
</HeaderTemplate>
					
<ItemTemplate>
    <asp:Label ID="lblName" Runat="server" Text='<%# Container.DataItem("name") %>' />					
</ItemTemplate>
</asp:TemplateField>

I can make the page look correct and the Image button calls back to the server with it's command event just fine. But I can't figure out how to access the contents of the text box. In .net 1.1 I'd just do this:

VB.NET:
Dim tbDescription As System.Web.UI.WebControls.TextBox
tbSearchName = e.Item.FindControl("txtSearchName")

But aparently my txtSearchName does not actually exist so I bomb when I try to read the ".text" property.

I've tried looking this up on the web and no one else seems to do it. The MSDN sight keeps crashing and I'm about to pull my hair out.

Can anyone suggest a solution or point me to an artical not on the MSDN website?
 
I found that the MSDN site crashes as well. I find that it only crashes in IE6, not tested IE7, but have used Opera. Good luck though!
 
Problem solved!!!

the code for my search button looks like this
VB.NET:
If e.CommandName = "SearchNames" Then
                Dim textbox1 As New System.Web.UI.WebControls.TextBox
                Dim cn As New SqlClient.SqlConnection
                Dim cmd As New SqlClient.SqlCommand
                Dim ds As New DataSet
                Dim da As New SqlClient.SqlDataAdapter

                Try
                    textbox1 = gvAdds.HeaderRow.Cells(0).FindControl("txtSearchName")
                    cn.ConnectionString = sqlConnStr
                    cn.Open()
                    If cn.State = ConnectionState.Open Then
                        sb.Append("SELECT fields FROM table WHERE filter")

                        cmd.Connection = cn
                        cmd.CommandType = CommandType.Text
                        cmd.CommandText = sb.ToString()

                        da.SelectCommand = cmd
                        da.Fill(ds, "AddTable")

                        gvAdds.DataSource = ds
                        gvAdds.DataBind()
                    End If

Basically you have to search the header row of the dataview by using the dataview name as the view itself is not part of the object passed to the CommandEvent handler.

AS for MSDN dieing the following link gave me instructions on how to fix it. http://support.microsoft.com/kb/946627
of course I had to find the solution at home, print of the document and bring it to work, since I couldn't even get to msnbc.com from work since the update. Way to Go, Microsoft!!!!:)
 
Back
Top