12 Replies - 1673 Views - Last Post: 18 June 2011 - 05:56 AM Rate Topic: -----

#1 raghucse2010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 11

i am new to this forum , i want to perform search button for home page

Posted 14 June 2011 - 10:37 PM

this is what i included in c#


 protected void ButtonSearch_Click(object sender, EventArgs e)
            
        {

            if (Textcomp_code.Text != "Select")
{
    SqlDataSource1.SelectCommand = "SELECT * FROM [cic] where Companyname like '%" + Textcomp_code.Text + "%'";

}


    }

        protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            SqlDataSource1.SelectCommand = "SELECT [Companyname], [Officeaddress], [id] FROM [cic] WHERE ([Companyname] LIKE '%' + @Companyname + '%')";
        }

        
    }



this is i included in ASP.NET

<asp:GridView 
        ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" 
        DataSourceID="SqlDataSource1">
        <Columns>
            <asp:BoundField DataField="Companyname" HeaderText="Companyname" 
                SortExpression="Companyname" />
            <asp:BoundField DataField="Officeaddress" HeaderText="Officeaddress" 
                SortExpression="Officeaddress" />
            <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
                ReadOnly="True" SortExpression="id" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:iqc_updatedConnectionString %>" 
        onselecting="SqlDataSource1_Selecting" 
        SelectCommand="SELECT [Companyname], [Officeaddress], [id] FROM [cic] WHERE ([Companyname] LIKE '%' + @Companyname + '%')">
        <SelectParameters>
            <asp:QueryStringParameter Name="Companyname" QueryStringField="Textcomp_code" 
                Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>



i have a text box and search button the input will be companyname for search

the problem i am facing is when click on search button it refreshes
i hope that you will guide me to get it work

Is This A Good Question/Topic? 0
  • +

Replies To: i am new to this forum , i want to perform search button for home page

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: i am new to this forum , i want to perform search button for home page

Posted 15 June 2011 - 03:32 AM

Moved to ASP.NET
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: i am new to this forum , i want to perform search button for home page

Posted 15 June 2011 - 04:33 AM

Ok. So the page refreshes when you click the button. What now? What are you expecting it to do? Any error messages?
Was This Post Helpful? 0
  • +
  • -

#4 raghucse2010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 11

Re: i am new to this forum , i want to perform search button for home page

Posted 15 June 2011 - 06:42 AM

thanks for response , i am not getting any error messages but the problem as per my knowledge was the home page uses a from which is runat server and i am using another form to use grid view which is runat server

when i compile it removing runat server it doesn't shows any error and refreshes the page when i click on search button
<form id="form1 runat="server">
but if i compile with out removing runat server it throws following error

A page can have only one server-side Form tag.??


can u suggest me what to do ?
-----------

View Posteclipsed4utoo, on 15 June 2011 - 04:33 AM, said:

Ok. So the page refreshes when you click the button. What now? What are you expecting it to do? Any error messages?

Was This Post Helpful? 0
  • +
  • -

#5 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: i am new to this forum , i want to perform search button for home page

Posted 15 June 2011 - 07:55 PM

you can only have one form with the runat="server" property on an aspx page and you shouldn't need any other form in the page either. If you're using a TextBox control to allow the user to search you would usually use a ControlParameter instead of a QueryStringParameter and set the TargetControlID parameter of the ControlParameter to the ID of the TextBox. In fact, doing it this way you don't even need any code behind code to handle the search since it will automatically apply the text in the textbox to the parameter during the postback caused by the button click. Also, it looks like you are setting the select statement during the button click and during the Selecting event of the data source. That doesn't really accomplish anything though. It will change the select statement during the button click event but then it will call the selecting event right after that and just change it again.

<asp:GridView 
        ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" 
        DataSourceID="SqlDataSource1">
        <Columns>
            <asp:BoundField DataField="Companyname" HeaderText="Companyname" 
                SortExp<b></b>ression="Companyname" />
            <asp:BoundField DataField="Officeaddress" HeaderText="Officeaddress" 
                SortExp<b></b>ression="Officeaddress" />
            <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
                ReadOnly="True" SortExp<b></b>ression="id" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:iqc_updatedConnectionString %>" 
        SelectCommand="SELECT [Companyname], [Officeaddress], [id] FROM [cic] WHERE ([Companyname] LIKE '%' + @Companyname + '%')">
        <SelectParameters>
            <asp:controlparameter name="Companyname" controlid="TextBoxID" propertyname="Text"/>
        </SelectParameters>
    </asp:SqlDataSource>


You'll need to change "TextBoxID" to the actual ID of your text box if that's the type of control you're using to allow the user's to search. You also shouldn't need to define either the onselecting event from the data source or the Click event from the button.
Was This Post Helpful? 0
  • +
  • -

#6 raghucse2010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 11

Re: i am new to this forum , i want to perform search button for home page

Posted 15 June 2011 - 11:23 PM

thanks Nakor,
i tried changing QueryStringParameter to controlparamater it throws an error

pointing to this
" SortExp<b></b>ression="...." " what is wrong with this ??

and i delete that it is working fine now,showing records into grid view on user search into textbox

i have one more question to ask but it might be a silly question i am asking it on the because i don't know it

my question is can i give css style or any color to the grid view

thanks once again , hoping for response
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: i am new to this forum , i want to perform search button for home page

Posted 16 June 2011 - 02:24 AM

Yes, you can style a GridView using CSS. Here is a sample on how to do it.

http://www.atashbaha...-using-CSS.aspx
Was This Post Helpful? 0
  • +
  • -

#8 raghucse2010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 11

Re: i am new to this forum , i want to perform search button for home page

Posted 16 June 2011 - 03:08 AM

thanks for you reply .i have already added in that in properties as per my client request in properties using edit columns ,

---for your information my website is a certification issuing home page consists of table which shows list of companies and their status and this grid view is extra one added for showing the search results ---

client says the content that was in home page has to disappear leaving and only search results

is it possible can any one guide me to achieve that
Was This Post Helpful? 0
  • +
  • -

#9 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: i am new to this forum , i want to perform search button for home page

Posted 16 June 2011 - 04:45 AM

Quote

SortExp<b></b>ression="...."

It says "..."? I don't see any of your columns above that ahve a SortExpression="..." unless you changed one since you posted the code above.
Was This Post Helpful? 0
  • +
  • -

#10 raghucse2010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 11

Re: i am new to this forum , i want to perform search button for home page

Posted 16 June 2011 - 09:23 PM

its working now ,
can u guide me how to make search results only visible in home once user clicks on search button

Is it possible to make content disappear and search results only visible ?




View PostNakor, on 16 June 2011 - 04:45 AM, said:

Quote

SortExp<b></b>ression="...."

It says "..."? I don't see any of your columns above that ahve a SortExpression="..." unless you changed one since you posted the code above.

Was This Post Helpful? 0
  • +
  • -

#11 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: i am new to this forum , i want to perform search button for home page

Posted 16 June 2011 - 09:40 PM

you might try changing your select statement to something like

SELECT [Companyname], [Officeaddress], [id] FROM [cic] WHERE (@Companyname IS NOT NULL && [Companyname] LIKE '%' + @Companyname + '%')"



then if the @Companyname variable is null you should get back no results, another option would be to give @Companyname a default value and check for that default value instead of checking for null
Was This Post Helpful? 0
  • +
  • -

#12 raghucse2010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 11

Re: i am new to this forum , i want to perform search button for home page

Posted 16 June 2011 - 11:49 PM

i tried it nakor its not working its shows both search results

let me make it clear for you

i tried below code this in grid view datasource ---it searches what i am giving input and working fine

SelectCommand="SELECT cic.Companyname, sta.status, cic.Workaddress, cic.Officeaddress FROM new_process AS new INNER JOIN status_master AS sta ON new.status_id = sta.id INNER JOIN cic AS cic ON new.id = cic.process_id WHERE (cic.Companyname LIKE '%' + @Companyname + '%')">

but i have sql statement in page_onload function in my home.cs file which gives data once if i click on home page in my website

the statement given in home.cs file is :

string cstr = "SELECT cic.*,new.*,ncon.*,ncon.status_id as stat,ncon.contract_id as cont_id,ncon.next_page as np,cic.process_id as proc_id FROM new_process new, cic cic, new_cont ncon where cic.process_id=ncon.process_id and new.id=cic.process_id ";

and this in else statement

string cstr1 = "SELECT * FROM new_process new, status_master sta, cic cic where new.status_id=sta.id and new.id=cic.process_id and cic.process_id not in (select process_id from new_cont nc)";

file:///C:/Documents%20and%20Settings/Administrator/Desktop/home.bmp
after search it is
file:///C:/Documents%20and%20Settings/Administrator/Desktop/aftersearch.bmp

i hope nakor u r clear what my problem is ,expecting for some guidance



View PostNakor, on 16 June 2011 - 09:40 PM, said:

you might try changing your select statement to something like

SELECT [Companyname], [Officeaddress], [id] FROM [cic] WHERE (@Companyname IS NOT NULL && [Companyname] LIKE '%' + @Companyname + '%')"



then if the @Companyname variable is null you should get back no results, another option would be to give @Companyname a default value and check for that default value instead of checking for null

Was This Post Helpful? 0
  • +
  • -

#13 raghucse2010   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 11

Re: i am new to this forum , i want to perform search button for home page

Posted 18 June 2011 - 05:56 AM

thanks i got that by changing
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1