Hello All,
I have a SQLDataSource "sdsX" which has four records. There is a DataList "dlX" which is binded to this SQLDataSource "sdsX". Now I want that my datalist "dlX" take third record of "sdsX" as its first element. Is there any property which can be used.
Thanks
Hi ShailAtlas,
Base on my understanding, you want to move the third row to first row in DataList. For example:
Here is a DataList rendered likes below:
----------
1 | name1 |
----------
2 | name2 |
----------
3 | name3 |
----------
4 | name4 |
----------
You want to render it likes below without any change of datasource.
----------
3 | name3 |
----------
1 | name1 |
----------
2 | name2 |
----------
4 | name4 |
----------
If I have misunderstood your concern, please feel free to let me know.
DataList doesn't have property for this special request. If you want to implement it, you should add your own code in DataList_PreRender event handler. Here is the sample code:
int i = 0;
protectedvoid Page_Load(object sender,EventArgs e)
{
DataList1.DataBind();
}
protectedvoid Button1_Click(object sender,EventArgs e)
{
i =int.Parse(TextBox1.Text);
}
protectedvoid DataList1_PreRender(object sender,EventArgs e)
{
if (i != 0)
{
int j = i - 1;
string backupid = ((Label)DataList1.Items[j].Controls[1]).Text;
string backupname = ((Label)DataList1.Items[j].Controls[3]).Text;
for (; j > 0; j--)
{
((Label)DataList1.Items[j].Controls[1]).Text = ((Label)DataList1.Items[j-1].Controls[1]).Text;
((Label)DataList1.Items[j].Controls[3]).Text = ((Label)DataList1.Items[j-1].Controls[3]).Text;
}
((Label)DataList1.Items[0].Controls[1]).Text = backupid;
((Label)DataList1.Items[0].Controls[3]).Text = backupname;
}
}
When you input 3 in TextBox1 and then press Button1. DataList begin to render with the special order.
Hello Ben,
Lets understand like this.I have a SQLDataSource which has 4 records. Now I have 2 datalist say DataListX and DataListY.
I want that DataListX should show record number 1 & 2, and DataListY should show records 3 & 4
SQLDataSource has records like this
----------
1 | name1 |
----------
2 | name2 |
----------
3 | name3 |
----------
4 | name4 |
----------
Now DataListX will show like this
----------
1 | name1 |
----------
2 | name2 |
And DataListY should be like this
----------
3 | name3 |
----------
4 | name4 |
Intention is that I do not want to use 2 SQLDataSource for same type of records
Thanks for your Reply
Shail
No comments:
Post a Comment