How to use Dataview and bind the Gridview with like Query.

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 4344
hi

I have post the sample How to use Dataview and bind the Gridview with like Query.

Client Side Code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px" OnRowCommand="GridView1_RowCommand"
CellPadding="4" DataKeyNames="ProductID"
ForeColor="#333333">

<Columns>

<asp:BoundField DataField="ProductID" HeaderText="ProductID"
SortExpression="ProductID" />

<asp:ButtonField ButtonType="link" CommandName="ProductName"
DataTextField="ProductName" HeaderText="Name"
SortExpression="ProductName" />

<asp:ButtonField ButtonType="button" CommandName="MoreDetail"
HeaderText="More Details" Text="More Details" />

<asp:ButtonField ButtonType="Link" CommandName="ViewCategory"
HeaderText="View Category" Text="View Category" />

<asp:ButtonField ButtonType="Image" CommandName="BuyNow"
HeaderText="Buy Now" ImageUrl="buynow.gif" />

<asp:ButtonField DataTextField="UnitsInStock" HeaderText="Stock"
ButtonType="button" DataTextFormatString="{0} Items"
CommandName="Stock" />


</Columns>

</asp:GridView>

Server Side

if (!IsPostBack)
{
sqlcon.Open();
SqlDataAdapter sqladp = new SqlDataAdapter("select * from [Products]", sqlcon);
sqladp.Fill(dt);
DataView dv = new DataView();
dv = dt.DefaultView;
//dv.RowFilter = "ProductName = 'Mouse'";
dv.RowFilter = "ProductName like '%Mouse%'";
GridView1.DataSource = dv;
GridView1.DataBind();
}

Comments or Responses

Login to post response