none
how to access data form search data RRS feed

  • Question

  • Hi

    I am using visual studio 2005 and sql server 2005

    i have problem when i search data form database like name and i want to when 

    i click on search Name it's show Details of the Name

    my code is

     

    using System;

    using System.Data;

    using System.Configuration;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.Data.SqlClient;

     

    public partial class _Default : System.Web.UI.Page 

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if (Request.QueryString["searchString"] != null)

            {

                DisplaySearchResults(Request.QueryString["searchString"]);

            }

        }

     

        public void DisplaySearchResults(string strSearch)

        {

            SqlCommand cmd = new SqlCommand("spSearchByString", new SqlConnection(ConfigurationManager.AppSettings["RegpConnectionString"]));

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@SearchString", strSearch);

            cmd.Connection.Open();

     

            Repeater1.DataSource = cmd.ExecuteReader();

            Repeater1.DataBind();

     

            cmd.Connection.Close();

            cmd.Connection.Dispose();

        }

     

        protected void Button1_Click(object sender, EventArgs e)

        {

            Response.Redirect("Default.aspx?searchString=" + Server.UrlEncode(TextBox1.Text));

        }

    }

    and design code is:-
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Using Stored Procedures in ASP.NET 2.0 and C#.NET</title>
       
       <style type="text/css">
    <!--
    body {
     margin-left: 0px;
     margin-top: 0px;
     margin-right: 0px;
     margin-bottom: 0px;
    }
    a:link {
     color: #0000FF;
    }
    a:visited {
     color: #0000FF;
    }
    a:hover {
     color: #0000FF;
     text-decoration: none;
    }
    a:active {
     color: #0000FF;
     }
    .basix {
     font-family: Verdana, Arial, Helvetica, sans-serif;
     font-size: 11px;
    }
    .header1 {
     font-family: Verdana, Arial, Helvetica, sans-serif;
     font-size: 11px;
     font-weight: bold;
     color: #006699;
    }
    .lgHeader1 {
     font-family: Arial, Helvetica, sans-serif;
     font-size: 18px;
     font-weight: bold;
     color: #0066CC;
     background-color: #CEE9FF;
    }
    -->
    </style> 
    </head>
    <body>
      
            <br />
            &nbsp;<br />
            <table align="center" bgcolor="#5482fc" border="0" cellpadding="5" cellspacing="1"
                style="position: static; width: 692px;">
                <tr>
                    <td align="center" class="lgHeader1" height="50">
                        Search Database with String </td>
                </tr>
            </table>
            <br />
            <br />
            
        <fieldset style="width: 804px" align="center">
       
        <legend>Search Database with String</legend>
        <div align="left" style="text-align: center">
        <form id="form1" runat="server">This form will search for matching First Names and Last Name within the database.<br />
        Search: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
            <asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" /><br /><br />
            
            <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate><table width="100%"><tr><th>First Name</th><%--<th>Last Name</th>--%></tr></HeaderTemplate>
             <ItemTemplate>
                <tr><td><%#DataBinder.Eval(Container.DataItem, "Fname")%></a></td>
    <%--            <td><%#DataBinder.Eval(Container.DataItem, "Lname")%></td></tr>
    --%>         </ItemTemplate>
             <FooterTemplate></table></FooterTemplate>
        </asp:Repeater>
        </form>
        </div>
        </fieldset>    
    </body>
    </html>
        
        
            
            
        
       
    Please reply me
    Thanks in advance
    Regard

     


    Ramesh

    Thursday, June 16, 2011 7:01 AM

All replies

  • I think there are several problems here.

    First up.

    You're askinga  beginners asp.net questions in an architecture forum.

    Wrong forum mate.

     

    Second.

    You're learning obsolete technology.

     

    Third.

    You haven't explained what your problem is.

     

    Fourth.

    You're using response.redirect to what looks like the same form,  which is just weird.


    Thursday, June 16, 2011 9:00 AM
  • Thanks for reply

    Because , i am new about msdn forum


    Ramesh
    Thursday, June 16, 2011 10:32 AM