Searching Code on button event For Grid row data
<p>Actually i have generated a Grid (with Edit delete Select) through Data base property/sqldatasource1. and its working well..
 But only the problem is in.. i want some search button here with text boxes (in design page). while i coded on image button event initially it was throwing sqldatasource defination duplicacy, i tried every Possible thing But still its not working every time throwing some new error.</p>

<p>For this i have putted the following code inside .CS Page 
 but its not working please help me.</p>

<p><strong>.CS code for searching/Displaying the data, on button click after putting the column name in text box :</strong></p>

<pre><code> protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("Select h_id as 'Hoarding ID', Address,Size as 'Hoarding Size', State, District, Cost as 'Hoarding Cost', Pincode,From_date as 'Available From', To_date as 'Available To', hoarding_type as 'Hoarding Type', Lightboxes_type as 'Light Boxes', hoarding_image as 'Hoarding Image' from providers_post where h_id = '"+ TextBox1.Text+"'  ",con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataTable dt = new DataTable();
                      dt =ds.Tables[0];
         if (dt.Rows.Count  &gt; 0)
            {

              GridView1.DataSourceID = "SqlDataSource1";
              GridView1.DataBind();

            }
            else
            {
            //Response.Write("&lt;script&gt;alert('No data Available')&lt;/script&gt;");
            Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('No Data Available.');", true);
            }
            con.Close();

           }
</code></pre>

<p><strong>And SqlDataSource1 code fetching from designing(ASPX) page:</strong></p>

<pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="#CCCCCC" 
        BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" 
        CellSpacing="2" ForeColor="Black" Width="1100" AllowSorting="True" 
        DataSourceID="SqlDataSource1" ondatabound="GridView1_DataBound" &gt;
        &lt;footerstyle backcolor="#CCCCCC" wrap="False" /&gt;
        &lt;rowstyle backcolor="White" /&gt;


&lt;columns&gt;
&lt;asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" /&gt;


&lt;asp:TemplateField HeaderText="View Image"&gt;
&lt;itemtemplate&gt;
&lt;div id="gallery"&gt; &lt;!--Light boxes start--&gt;
&lt;ul&gt;
     &lt;li&gt;
&lt;a href="&lt;%# DataBinder.Eval (Container.DataItem, " hoarding_image=") %&gt;"&gt;
&lt;span style="text-align:center; margin-removed10px; float:left;"&gt;View Image&lt;/span&gt;
&lt;/a&gt;
    &lt;/li&gt;
&lt;/ul&gt;
&lt;%--&lt;a href="&lt;%# DataBinder.Eval(Container.DataItem, " hoarding_image=") %&gt;"&gt;IMAGE&lt;/a&gt;--%&gt;   &lt;!-- this code also is able to display litght box images inside Grid&gt;


&lt;/div&gt;&lt;!--Light boxes End--&gt;
&lt;/itemtemplate&gt;

&lt;/columns&gt;


    &lt;pagerstyle backcolor="#CCCCCC" forecolor="Black" wrap="True" /&gt;
    &lt;SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" 
            Wrap="True" /&gt;
    &lt;HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /&gt;
        &lt;alternatingrowstyle horizontalalign="Left" wrap="False" /&gt;









    &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConflictDetection="CompareAllValues" 
        ConnectionString="&lt;%$ ConnectionStrings:HoardingIndiaConnectionString %&gt;" 
        DeleteCommand="DELETE FROM [providers_post] WHERE [h_id] = @original_h_id AND (([Address] = @original_Address) OR ([Address] IS NULL AND @original_Address IS NULL)) AND (([Details] = @original_Details) OR ([Details] IS NULL AND @original_Details IS NULL)) AND (([Size] = @original_Size) OR ([Size] IS NULL AND @original_Size IS NULL)) AND (([State] = @original_State) OR ([State] IS NULL AND @original_State IS NULL)) AND (([District] = @original_District) OR ([District] IS NULL AND @original_District IS NULL)) AND (([Landmark] = @original_Landmark) OR ([Landmark] IS NULL AND @original_Landmark IS NULL)) AND (([Cost] = @original_Cost) OR ([Cost] IS NULL AND @original_Cost IS NULL)) AND (([Pincode] = @original_Pincode) OR ([Pincode] IS NULL AND @original_Pincode IS NULL)) AND (([From_date] = @original_From_date) OR ([From_date] IS NULL AND @original_From_date IS NULL)) AND (([To_date] = @original_To_date) OR ([To_date] IS NULL AND @original_To_date IS NULL)) AND (([hoarding_type] = @original_hoarding_type) OR ([hoarding_type] IS NULL AND @original_hoarding_type IS NULL)) AND (([hoarding_image] = @original_hoarding_image) OR ([hoarding_image] IS NULL AND @original_hoarding_image IS NULL)) AND (([Lightboxes_type] = @original_Lightboxes_type) OR ([Lightboxes_type] IS NULL AND @original_Lightboxes_type IS NULL)) AND (([Valid] = @original_Valid) OR ([Valid] IS NULL AND @original_Valid IS NULL))" 
        InsertCommand="INSERT INTO [providers_post] ([Address], [Details], [Size], [State], [District], [Landmark], [Cost], [Pincode], [From_date], [To_date], [hoarding_type], [hoarding_image], [Lightboxes_type], [Valid]) VALUES (@Address, @Details, @Size, @State, @District, @Landmark, @Cost, @Pincode, @From_date, @To_date, @hoarding_type, @hoarding_image, @Lightboxes_type, @Valid)" 
        OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT [h_id], [Address], [Details], [Size], [State], [District], [Landmark], [Cost], [Pincode], [From_date], [To_date], [hoarding_type], [hoarding_image], [Lightboxes_type], [Valid] FROM [providers_post] ORDER BY [h_id]" 

        UpdateCommand="UPDATE [providers_post] SET [Address] = @Address, [Details] = @Details, [Size] = @Size, [State] = @State, [District] = @District, [Landmark] = @Landmark, [Cost] = @Cost, [Pincode] = @Pincode, [From_date] = @From_date, [To_date] = @To_date, [hoarding_type] = @hoarding_type, [hoarding_image] = @hoarding_image, [Lightboxes_type] = @Lightboxes_type, [Valid] = @Valid WHERE [h_id] = @original_h_id AND (([Address] = @original_Address) OR ([Address] IS NULL AND @original_Address IS NULL)) AND (([Details] = @original_Details) OR ([Details] IS NULL AND @original_Details IS NULL)) AND (([Size] = @original_Size) OR ([Size] IS NULL AND @original_Size IS NULL)) AND (([State] = @original_State) OR ([State] IS NULL AND @original_State IS NULL)) AND (([District] = @original_District) OR ([District] IS NULL AND @original_District IS NULL)) AND (([Landmark] = @original_Landmark) OR ([Landmark] IS NULL AND @original_Landmark IS NULL)) AND (([Cost] = @original_Cost) OR ([Cost] IS NULL AND @original_Cost IS NULL)) AND (([Pincode] = @original_Pincode) OR ([Pincode] IS NULL AND @original_Pincode IS NULL)) AND (([From_date] = @original_From_date) OR ([From_date] IS NULL AND @original_From_date IS NULL)) AND (([To_date] = @original_To_date) OR ([To_date] IS NULL AND @original_To_date IS NULL)) AND (([hoarding_type] = @original_hoarding_type) OR ([hoarding_type] IS NULL AND @original_hoarding_type IS NULL)) AND (([hoarding_image] = @original_hoarding_image) OR ([hoarding_image] IS NULL AND @original_hoarding_image IS NULL)) AND (([Lightboxes_type] = @original_Lightboxes_type) OR ([Lightboxes_type] IS NULL AND @original_Lightboxes_type IS NULL)) AND (([Valid] = @original_Valid) OR ([Valid] IS NULL AND @original_Valid IS NULL))"&gt;
        &lt;deleteparameters&gt;
            &lt;asp:Parameter Name="original_h_id" Type="Int32" /&gt;
            &lt;asp:Parameter Name="original_Address" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Details" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Size" Type="String" /&gt;
            &lt;asp:Parameter Name="original_State" Type="String" /&gt;
            &lt;asp:Parameter Name="original_District" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Landmark" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Cost" Type="Decimal" /&gt;
            &lt;asp:Parameter Name="original_Pincode" Type="String" /&gt;
            &lt;asp:Parameter Name="original_From_date" Type="String" /&gt;
            &lt;asp:Parameter Name="original_To_date" Type="String" /&gt;
            &lt;asp:Parameter Name="original_hoarding_type" Type="String" /&gt;
            &lt;asp:Parameter Name="original_hoarding_image" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Lightboxes_type" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Valid" Type="String" /&gt;
        &lt;/deleteparameters&gt;
        &lt;updateparameters&gt;
            &lt;asp:Parameter Name="Address" Type="String" /&gt;
            &lt;asp:Parameter Name="Details" Type="String" /&gt;
            &lt;asp:Parameter Name="Size" Type="String" /&gt;
            &lt;asp:Parameter Name="State" Type="String" /&gt;
            &lt;asp:Parameter Name="District" Type="String" /&gt;
            &lt;asp:Parameter Name="Landmark" Type="String" /&gt;
            &lt;asp:Parameter Name="Cost" Type="Decimal" /&gt;
            &lt;asp:Parameter Name="Pincode" Type="String" /&gt;
            &lt;asp:Parameter Name="From_date" Type="String" /&gt;
            &lt;asp:Parameter Name="To_date" Type="String" /&gt;
            &lt;asp:Parameter Name="hoarding_type" Type="String" /&gt;
            &lt;asp:Parameter Name="hoarding_image" Type="String" /&gt;
            &lt;asp:Parameter Name="Lightboxes_type" Type="String" /&gt;
            &lt;asp:Parameter Name="Valid" Type="String" /&gt;
            &lt;asp:Parameter Name="original_h_id" Type="Int32" /&gt;
            &lt;asp:Parameter Name="original_Address" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Details" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Size" Type="String" /&gt;
            &lt;asp:Parameter Name="original_State" Type="String" /&gt;
            &lt;asp:Parameter Name="original_District" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Landmark" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Cost" Type="Decimal" /&gt;
            &lt;asp:Parameter Name="original_Pincode" Type="String" /&gt;
            &lt;asp:Parameter Name="original_From_date" Type="String" /&gt;
            &lt;asp:Parameter Name="original_To_date" Type="String" /&gt;
            &lt;asp:Parameter Name="original_hoarding_type" Type="String" /&gt;
            &lt;asp:Parameter Name="original_hoarding_image" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Lightboxes_type" Type="String" /&gt;
            &lt;asp:Parameter Name="original_Valid" Type="String" /&gt;
        &lt;/updateparameters&gt;
        &lt;insertparameters&gt;
            &lt;asp:Parameter Name="Address" Type="String" /&gt;
            &lt;asp:Parameter Name="Details" Type="String" /&gt;
            &lt;asp:Parameter Name="Size" Type="String" /&gt;
            &lt;asp:Parameter Name="State" Type="String" /&gt;
            &lt;asp:Parameter Name="District" Type="String" /&gt;
            &lt;asp:Parameter Name="Landmark" Type="String" /&gt;
            &lt;asp:Parameter Name="Cost" Type="Decimal" /&gt;
            &lt;asp:Parameter Name="Pincode" Type="String" /&gt;
            &lt;asp:Parameter Name="From_date" Type="String" /&gt;
            &lt;asp:Parameter Name="To_date" Type="String" /&gt;
            &lt;asp:Parameter Name="hoarding_type" Type="String" /&gt;
            &lt;asp:Parameter Name="hoarding_image" Type="String" /&gt;
            &lt;asp:Parameter Name="Lightboxes_type" Type="String" /&gt;
            &lt;asp:Parameter Name="Valid" Type="String" /&gt;
        &lt;/insertparameters&gt;
</code></pre>
