Click here to Skip to main content
14,937,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Every One,
Good afternoon!!

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.

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

.CS code for searching :

C#
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  > 0)
      {
          //GridView1.DataSource = null;
          //GridView1.DataSource = dt;
          ////GridView1.DataBind();


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




          //GridView1.DataSourceID = "SqlDataSource1";
          ////GridView1.DataBind();
      }
      else
      {
      //Response.Write("<script>alert('No data Available')</script>");
      Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('No Data Available.');", true);
      }
      con.Close();






  }

And SqlDataSource1 code fetching from designing(ASPX) page:


ASP.NET
<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" >
        <footerstyle backcolor="#CCCCCC" wrap="False" />
        <rowstyle backcolor="White" />


<columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />


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


</div><!--Light boxes End-->
</itemtemplate>

</columns>


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








    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:HoardingIndiaConnectionString %>" 
        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))">
        <deleteparameters>
            <asp:Parameter Name="original_h_id" Type="Int32" />
            <asp:Parameter Name="original_Address" Type="String" />
            <asp:Parameter Name="original_Details" Type="String" />
            <asp:Parameter Name="original_Size" Type="String" />
            <asp:Parameter Name="original_State" Type="String" />
            <asp:Parameter Name="original_District" Type="String" />
            <asp:Parameter Name="original_Landmark" Type="String" />
            <asp:Parameter Name="original_Cost" Type="Decimal" />
            <asp:Parameter Name="original_Pincode" Type="String" />
            <asp:Parameter Name="original_From_date" Type="String" />
            <asp:Parameter Name="original_To_date" Type="String" />
            <asp:Parameter Name="original_hoarding_type" Type="String" />
            <asp:Parameter Name="original_hoarding_image" Type="String" />
            <asp:Parameter Name="original_Lightboxes_type" Type="String" />
            <asp:Parameter Name="original_Valid" Type="String" />
        </deleteparameters>
        <updateparameters>
            <asp:Parameter Name="Address" Type="String" />
            <asp:Parameter Name="Details" Type="String" />
            <asp:Parameter Name="Size" Type="String" />
            <asp:Parameter Name="State" Type="String" />
            <asp:Parameter Name="District" Type="String" />
            <asp:Parameter Name="Landmark" Type="String" />
            <asp:Parameter Name="Cost" Type="Decimal" />
            <asp:Parameter Name="Pincode" Type="String" />
            <asp:Parameter Name="From_date" Type="String" />
            <asp:Parameter Name="To_date" Type="String" />
            <asp:Parameter Name="hoarding_type" Type="String" />
            <asp:Parameter Name="hoarding_image" Type="String" />
            <asp:Parameter Name="Lightboxes_type" Type="String" />
            <asp:Parameter Name="Valid" Type="String" />
            <asp:Parameter Name="original_h_id" Type="Int32" />
            <asp:Parameter Name="original_Address" Type="String" />
            <asp:Parameter Name="original_Details" Type="String" />
            <asp:Parameter Name="original_Size" Type="String" />
            <asp:Parameter Name="original_State" Type="String" />
            <asp:Parameter Name="original_District" Type="String" />
            <asp:Parameter Name="original_Landmark" Type="String" />
            <asp:Parameter Name="original_Cost" Type="Decimal" />
            <asp:Parameter Name="original_Pincode" Type="String" />
            <asp:Parameter Name="original_From_date" Type="String" />
            <asp:Parameter Name="original_To_date" Type="String" />
            <asp:Parameter Name="original_hoarding_type" Type="String" />
            <asp:Parameter Name="original_hoarding_image" Type="String" />
            <asp:Parameter Name="original_Lightboxes_type" Type="String" />
            <asp:Parameter Name="original_Valid" Type="String" />
        </updateparameters>
        <insertparameters>
            <asp:Parameter Name="Address" Type="String" />
            <asp:Parameter Name="Details" Type="String" />
            <asp:Parameter Name="Size" Type="String" />
            <asp:Parameter Name="State" Type="String" />
            <asp:Parameter Name="District" Type="String" />
            <asp:Parameter Name="Landmark" Type="String" />
            <asp:Parameter Name="Cost" Type="Decimal" />
            <asp:Parameter Name="Pincode" Type="String" />
            <asp:Parameter Name="From_date" Type="String" />
            <asp:Parameter Name="To_date" Type="String" />
            <asp:Parameter Name="hoarding_type" Type="String" />
            <asp:Parameter Name="hoarding_image" Type="String" />
            <asp:Parameter Name="Lightboxes_type" Type="String" />
            <asp:Parameter Name="Valid" Type="String" />
        </insertparameters>
Posted
Updated 19-Feb-13 22:41pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900