TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhimanyu Singh
NA
116
49.2k
Search the grid row data....
Feb 18 2013 3:03 AM
Hello budy,
Gud noon to every one!!
Actually i have generated/bind a Grid (insert update delete) through Data base property/sqldatasource1. and its working well now
But i want to put the some code in c# so that i can search any row data by putting their columnname in text boxes.
For this i have putted the following code insde
.CS Page
but its not working please help me.
.CS code for searching :
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 from designing page
<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-top:10px; 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>
</asp:TemplateField>
</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:GridView>
<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" />
</Up
dateParameters>
<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>
</asp:SqlDataSource>
Reply
Answers (
11
)
How to select values from 4 chekboxes C#
uploading ms word document as blob