TreeNode tr =
new TreeNode(dr[
"category_name"].ToString());
TreeView1.Nodes.Add(tr);
//string str="select sub_cat_name from sub_category where cat_id=(select cat_id from category where category_name='"+TreeView1.SelectedNode.Value+"')";
string str = "select * from sub_category where cat_id='" + dr[ "cat_id"].ToString()
+ "'";
da =
new SqlDataAdapter(str, con);
ds =
new DataSet();
da.Fill(ds,
"aa");
foreach (DataRow dd
in ds.Tables[
"aa"].Rows)
{
TreeNode t1 =
new TreeNode(dd[
"sub_cat_name"].ToString());
tr.ChildNodes.Add(t1);
string ss = "select * from product where sub_cat_id='" + dd[ "sub_cat_id"] +
"'";
da =
new SqlDataAdapter(ss, con);
ds =
new DataSet();
da.Fill(ds,
"as");
foreach (DataRow df
in ds.Tables[
"as"].Rows)
{
TreeNode t2 =
new TreeNode(df[
"product_name"].ToString());
t1.ChildNodes.Add(t2);
}
}
//TreeView1.DataSource = ds.Tables["s"];
//TreeView1.DataBind();
}
}
public void rep()
{
string s = "select * from category";
da =
new SqlDataAdapter(s, con);
ds =
new DataSet();
da.Fill(ds,
"s");
Repeater1.DataSource = ds.Tables[
"s"];
Repeater1.DataBind();
//string st = "select * from sub_category where cat_id='"+Repeater1";
You can enable the sorting to true in design mode of gridview. Also for each boundfield, provide a sort expression. Now depending on the sorting expression you can query the database.
usman531
Member
16 Points
4 Posts
How to sort data into GridView
Jan 16, 2008 12:12 PM|LINK
DataView DV = DT.DefaultView;DV.Sort =
"FullName";by writing these two lines you can sort the data into dataview sorting data into dataview is fast and easer
Usman
view my blog: http://usman-bhatti.blogspot.com
murthysrn
Participant
1142 Points
397 Posts
Re: How to sort data into GridView
Jan 16, 2008 01:52 PM|LINK
hi,
Reload teh dataview by sorting the dataset/Datatable with the clicked value.
or change teh view to Grid and again reload at every time with the sorting colum header/adn default column header .
Murthy.
gyana.ojha
Participant
770 Points
380 Posts
Re: How to sort data into GridView
Jan 21, 2008 11:35 AM|LINK
}
Thanks & Regard
Gyana Ojha
KBNSarma
Member
192 Points
67 Posts
Re: How to sort data into GridView
Jan 22, 2008 04:06 AM|LINK
Please note, your sorting will be effective only if you select the PrimaryKey Item in your query string.
KBN Sarma
codeNickel
Member
108 Points
35 Posts
Re: How to sort data into GridView
Jan 23, 2008 04:29 AM|LINK
Sorting can be performed quite well even if you do not select the PrimaryKey Item in your query string.
Any of the data columns can be effectively sorted on.
KBNSarma
Member
192 Points
67 Posts
Re: How to sort data into GridView
Jan 23, 2008 04:45 AM|LINK
Thank you for your information. Earlier I tried, but it gave some problems.
Regards, KBN Sarma
rbansal44
Participant
1041 Points
245 Posts
Re: How to sort data into GridView
Feb 02, 2008 10:02 AM|LINK
using
System;using
System.Data;using
System.Configuration;using
System.Collections;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControlsusing
System.Web.UI.HtmlControls;using
System.Data.SqlClient;public
partial class treenrepeater : System.Web.UI.Page{
SqlConnection con = new SqlConnection (ConfigurationManager.AppSettings["conn"]);
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack){
tree();
rep();
int a = 9;Response.Write(a);
grd();
}
}
static void Main(string[] args){ }
public void tree(){
string s = "select * from category";da =
new SqlDataAdapter(s, con);ds =
new DataSet();da.Fill(ds,
"s");
//TreeView1.Parent = "f";
foreach (DataRow dr in ds.Tables[ "s"].Rows){
TreeNode tr = new TreeNode(dr[ "category_name"].ToString());TreeView1.Nodes.Add(tr);
//string str="select sub_cat_name from sub_category where cat_id=(select cat_id from category where category_name='"+TreeView1
string str = "select * from sub_category where cat_id='" + dr[ "cat_id"].ToString() + "'";da =
new SqlDataAdapter(str, con);ds =
new DataSet();da.Fill(ds,
"aa");
foreach (DataRow dd in ds.Tables[ "aa"].Rows){
TreeNode t1 = new TreeNode(dd[ "sub_cat_name"].ToString());tr.ChildNodes.Add(t1);
string ss = "select * from product where sub_cat_id='" + dd[ "sub_cat_id"] + "'";da =
new SqlDataAdapter(ss, con);ds =
new DataSet();da.Fill(ds,
"as");
foreach (DataRow df in ds.Tables[ "as"].Rows){
TreeNode t2 = new TreeNode(df[ "product_name"].ToString());t1.ChildNodes.Add(t2);
}
}
//TreeView1.DataSource = ds.Tables["s"];
//TreeView1.DataBind();}
}
public void rep(){
string s = "select * from category";da =
new SqlDataAdapter(s, con);ds =
new DataSet();da.Fill(ds,
"s");Repeater1.DataSource = ds.Tables[
"s"];Repeater1.DataBind();
//string st = "select * from sub_category where cat_id='"+Repeater1";
//da = new SqlDataAdapter(st, con);
//ds = new DataSet();
//da.Fill(ds, "s");}
protected void CustomValidator1_ServerValidate{
if (TextBox1.Text == "anish"){
args.IsValid =
true;Response.Write(
"abc");}
elseargs.IsValid =
false;}
protected void Button1_Click(object sender, EventArgs e){
//Response.Write(TextBox1.Text);}
protected void Button1_Click1(object sender, EventArgs e){
Response.Redirect(
"default.aspx?a="+TextBox1.Text);}
public void grd(){
string s = "select * from product";da =
new SqlDataAdapter(s, con);ds =
new DataSet();da.Fill(ds,
"s");GridView1.DataSource = ds.Tables[
"s"];GridView1.DataBind();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e){
//string s = GridView1.SortExpression;
//e.SortExpression = s;
SqlDataAdapter da1 = new SqlDataAdapter ("Select * from product",con);
DataTable dt = new DataTable();da1.Fill(dt);
DataView dv = new DataView(dt);
//dv.Sort
// GridView1.DataSource = dv.Sort;
//GridView1.DataBind();dv.Sort = e.SortExpression +
" " + "ASC";GridView1.DataSource = dv;
GridView1.DataBind();
//string s = GridView1.SortExpression;
//string r = e.SortExpression;
//if (s.IndexOf(r) < 0)
//{
// if (r.Length > 0)
// {
// e.SortExpression = r + "," + s;
// }
// else
// {
// e.SortExpression = r;
// }
//}
//else
//{
// e.SortExpression = s;
//}}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e){
}
}
nishantpawar
None
0 Points
2 Posts
Re: How to sort data into GridView
Feb 12, 2008 05:17 AM|LINK
Hi,
You can enable the sorting to true in design mode of gridview. Also for each boundfield, provide a sort expression. Now depending on the sorting expression you can query the database.
cprmnm
Member
2 Points
1 Post
Re: How to sort data into GridView
Feb 13, 2008 05:47 AM|LINK
To Sort the Items in asp.net data grid double click on the title tag. It will be get sorted.
tapamay@sipl
Member
6 Points
3 Posts
Re: How to sort data into GridView
Feb 23, 2008 05:26 AM|LINK
Is it so much difficult to implement sorting in GridView? Anyways, I think you can just use "sorting=True" in the properties of the gridview.
Sorry if my understanding is wrong on this query....
Software Developer
Saltlake Infosolutions Pvt. Ltd.
Kolkata,West-Bengal,India
My Company Site: http://www.saltlakesoft.com