Sir,
Please correct and send (ratlincomputers@gmail.com) to the following code, which is better to me.
Sample table:
Item Quantity Price Total
Saraca 12 5 60
Annona 8 10 80
Saraca 5 5 25
when I search Saraca using textbox control the gridview display like
Item Saraca Saraca
Quanttiy 12 5
Price 5 5
Total 60 25
Please help.
//code
// sample table fields are Item, Quantity, Price, Total
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="rowscolumns.aspx.vb" Inherits="VB" %>
<!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 id="Head1" runat="server">
<title></title>
<style type="text/css">
.Grid td
{
background-color: #eee;
color: black;
font-family: Arial;
font-size: 10pt;
line-height: 200%;
cursor: pointer;
width: 100px;
}
.header
{
background-color: #6C6C6C !important;
color: White !important;
font-family: Arial;
font-size: 10pt;
line-height: 200%;
width: 100px;
text-align:center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:GridView ID="GridView1" CssClass="Grid" HeaderStyle-CssClass = "header"
runat="server" AutoGenerateColumns = "False" DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="Item" HeaderText="Item" SortExpression="Item" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity"
SortExpression="Quantity" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="Total" HeaderText="Total" SortExpression="Total" />
</Columns>
<HeaderStyle CssClass="header"></HeaderStyle>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/thrissurplaces.mdb"
SelectCommand="SELECT * FROM [rowscolumns] WHERE ([Item] = ?)">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="Item" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:AccessDataSource>
<br />
</form>
</body>
</html>
// vb.net code
Imports System.Data
Partial Class VB
Inherits System.Web.UI.Page
Private Sub BindGrid(ByVal dt As DataTable, ByVal rotate As Boolean)
GridView1.ShowHeader = Not rotate
GridView1.DataSource = dt
GridView1.DataBind()
If rotate Then
For Each row As GridViewRow In GridView1.Rows
row.Cells(0).CssClass = "header"
Next
End If
End Sub
Protected Sub Convert(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = DirectCast(ViewState("dt"), DataTable)
If TryCast(sender, Button).CommandArgument = "1" Then
Dim dt2 As New DataTable()
For i As Integer = 0 To dt.Rows.Count
dt2.Columns.Add()
Next
For i As Integer = 0 To dt.Columns.Count - 1
dt2.Rows.Add()
dt2.Rows(i)(0) = dt.Columns(i).ColumnName
Next
For i As Integer = 0 To dt.Columns.Count - 1
For j As Integer = 0 To dt.Rows.Count - 1
dt2.Rows(i)(j + 1) = dt.Rows(j)(i)
Next
Next
BindGrid(dt2, True)
Else
BindGrid(dt, False)
End If
End Sub
End Class