Showing posts with label items. Show all posts
Showing posts with label items. Show all posts

Monday, March 26, 2012

Set display order of ListBox control

Hi
I have a ListBox control in my ASP.NET page. After I binding data to this
control, I would like to be able to change this display order of items in
this control. Just like change layout function of my.yahoo.com.
I tried client side approach, yes I can change display order by JavaScript,
but after clicking one of the button the display order will reverse back to
its original status. Because after PostBack, the page will try to render
this control by viewstate again.

I tried server side approach, but looks there is no way to switch two
ListItems programmatically.

Is there anybody who has some good idea?

Thanks!

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours HardyI already solved this problem.

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> Hi
> I have a ListBox control in my ASP.NET page. After I binding data to this
> control, I would like to be able to change this display order of items in
> this control. Just like change layout function of my.yahoo.com.
> I tried client side approach, yes I can change display order by
JavaScript,
> but after clicking one of the button the display order will reverse back
to
> its original status. Because after PostBack, the page will try to render
> this control by viewstate again.
> I tried server side approach, but looks there is no way to switch two
> ListItems programmatically.
>
> Is there anybody who has some good idea?
> Thanks!
> --
>
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
How?
--
Joe Fallon

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> I already solved this problem.
>
> "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > Hi
> > I have a ListBox control in my ASP.NET page. After I binding data to
this
> > control, I would like to be able to change this display order of items
in
> > this control. Just like change layout function of my.yahoo.com.
> > I tried client side approach, yes I can change display order by
> JavaScript,
> > but after clicking one of the button the display order will reverse back
> to
> > its original status. Because after PostBack, the page will try to render
> > this control by viewstate again.
> > I tried server side approach, but looks there is no way to switch two
> > ListItems programmatically.
> > Is there anybody who has some good idea?
> > Thanks!
> > --
> > WWW: http://hardywang.1accesshost.com
> > ICQ: 3359839
> > yours Hardy
Dump content of listbox to array, sort array in memory, then clear this
listbox and add listitem from array one by one.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Joe Fallon" <jfallon1@.nospamtwcny.rr.com> wrote in message
news:%23nd3uPALEHA.3052@.TK2MSFTNGP12.phx.gbl...
> How?
> --
> Joe Fallon
>
> "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> > I already solved this problem.
> > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > > Hi
> > > I have a ListBox control in my ASP.NET page. After I binding data to
> this
> > > control, I would like to be able to change this display order of items
> in
> > > this control. Just like change layout function of my.yahoo.com.
> > > I tried client side approach, yes I can change display order by
> > JavaScript,
> > > but after clicking one of the button the display order will reverse
back
> > to
> > > its original status. Because after PostBack, the page will try to
render
> > > this control by viewstate again.
> > > > I tried server side approach, but looks there is no way to switch two
> > > ListItems programmatically.
> > > > > Is there anybody who has some good idea?
> > > > Thanks!
> > > > --
> > > > > > WWW: http://hardywang.1accesshost.com
> > > ICQ: 3359839
> > > yours Hardy
> >
Yep.
That is what my listbox sort routine does.
Just wondering if you came up with something different.
--
Joe Fallon

"Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
news:uVlWuSFLEHA.3808@.TK2MSFTNGP12.phx.gbl...
> Dump content of listbox to array, sort array in memory, then clear this
> listbox and add listitem from array one by one.
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
> "Joe Fallon" <jfallon1@.nospamtwcny.rr.com> wrote in message
> news:%23nd3uPALEHA.3052@.TK2MSFTNGP12.phx.gbl...
> > How?
> > --
> > Joe Fallon
> > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > news:O7ZTxp$KEHA.2244@.tk2msftngp13.phx.gbl...
> > > I already solved this problem.
> > > > > "Hardy Wang" <hardy_wang@.marketrend.com> wrote in message
> > > news:upQn0K$KEHA.628@.TK2MSFTNGP11.phx.gbl...
> > > > Hi
> > > > I have a ListBox control in my ASP.NET page. After I binding data to
> > this
> > > > control, I would like to be able to change this display order of
items
> > in
> > > > this control. Just like change layout function of my.yahoo.com.
> > > > I tried client side approach, yes I can change display order by
> > > JavaScript,
> > > > but after clicking one of the button the display order will reverse
> back
> > > to
> > > > its original status. Because after PostBack, the page will try to
> render
> > > > this control by viewstate again.
> > > > > > I tried server side approach, but looks there is no way to switch
two
> > > > ListItems programmatically.
> > > > > > > > Is there anybody who has some good idea?
> > > > > > Thanks!
> > > > > > --
> > > > > > > > > > WWW: http://hardywang.1accesshost.com
> > > > ICQ: 3359839
> > > > yours Hardy
> > > > > >

Set DropDownList Items Alignment

Hi

How can I set my dropdownlist Itmes alignement right rether than left?

I bound them from a database??

my code

<asp:DropDownList width="100%" Runat="Server" ID="ddlCollege" DataTextField="CollegeName" Style="text-align: center;" DataValueField="CollegeID" Autopostback="True" OnSelectedIndexChanged="ShowDepartmentsEvents"/>

on the behind code I select values from the database??

Can Someone help??

thanks in advance

Setting style="text-align:right" on the dropdown list will work in Firefox, but I don't think there is any way to do this on Internet Explorer 6.

regards


I'm afraid you cannot do that unless you create you own dropdownlist :(

Hope my suggestion helps.

Tuesday, March 13, 2012

set multiview active on selection asp:menu item

I have an asp:menu with items in it and a multiview. I want to set the multiview pane depending on which menu item is clicked. Any ideas?

thanks

Andrew

Hi, ajw

Here are references :

http://blogs.vbcity.com/mcintyre/archive/2006/11/07/6773.aspx

http://www.codeproject.com/aspnet/TabControl.asp

Hope this helps


I already have a menu set up which I want to use.

So if i have an on menu clicked method then in that I want to set the multiview pane of (whatever) to active depending on which menu item is clicked.

Thanks for the help

Andrew


ajw:

I already have a menu set up which I want to use.

So if i have an on menu clicked method then in that I want to set the multiview pane of (whatever) to active depending on which menu item is clicked.

Thanks for the help

Andrew

Hi, andrew

This is for you:

ProtectedSub Menu1_MenuItemClick(ByVal senderAsObject,ByVal eAs MenuEventArgs)Handles Menu1.MenuItemClick

MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value)

Menu1.Items(0).ImageUrl ="~/Images/HomeDisabled.jpg"

Menu1.Items(1).ImageUrl ="~/Images/ProductsDisabled.jpg"

Menu1.Items(2).ImageUrl ="~/Images/SupportDisabled.jpg"

Menu1.Items(3).ImageUrl ="~/Images/HelpDisabled.jpg"

SelectCase e.Item.Value

Case 0

Menu1.Items(0).ImageUrl ="~/Images/HomeEnabled.jpg"

Case 1

Menu1.Items(1).ImageUrl ="~/Images/ProductsEnabled.jpg"

Case 2

Menu1.Items(2).ImageUrl ="~/Images/SupportEnabled.jpg"

Case 3

Menu1.Items(3).ImageUrl ="~/Images/HelpEnabled.jpg"

EndSelect

EndSub

//////////////////////////////////////

Please tell us if there is something else you have. Thanks

Hope this helps.


Can i use a query string ? e.g. mypage.aspx?multiview=1 because the menu I have is in a masterpage and the multiview is in a content page. I have used your examples to create a working model using that method. Thankyou.

Andrew


Can i use a query string ? e.g. mypage.aspx?multiview=1 because the menu I have is in a masterpage and the multiview is in a content page. I have used your examples to create a working model using that method. But have a problem in my scenario. Thankyou.

Andrew


Hi, Andrew

Are you looking this method?

protectedvoidXXX_SelectedIndexChanged(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = Convert.ToInt32(XXX.SelectedValue);
}

Hope this helps.


It doesnt work because it always says either the menu1 or the multiview1 is undeclared because the menu is on the masterpage and the multiview on the content page.

If I have a url of

e.gg

http://www.abtecnet.com/services.aspx?view=1

http://www.abtecnet.com/services.aspx?view=2

etc

Then cant I get the query string with Response.Write(Request.QueryString("view"))

And then somehow use that number to set the active index of the multiview?

Cheers

Andrew


If Ive got

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim viewstring As String
viewstring = Request.QueryString("view")

servicemultiview.setactiveindex()
End Sub

how do I set the active index to the value of the query string based on above?

Thanks

Andrew


Done it now

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim viewstring As Int32
viewstring = Request.QueryString("view")
servicemultiview.ActiveViewIndex = viewstring
End Sub

set selected value declaratively to dropdownlist

Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?
I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode
<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />
</EditItemTemplate>
I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any promptsHi,
You can set the selectedvalue property on the dropdownlist as follows
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddl"
DataSourceID="SqlDataSource2"
DataValueField="ProductID"
DataTextField="ProductName" SelectedValue='<%# Bind("ProductID")
%>'></asp:DropDownList>
</EditItemTemplate>
Regards,
Mohamed Mosalem
"podi" wrote:

> Hi,
> I just wonder if there is a way to set a selected item in dropdown list
> which items are retreived from database without touching c# code ?
> I mean, i have in gridview, in edit mode one dropdownlist which
> selected value should be the same as a label text from normal view mode
> <EditItemTemplate>
> <asp:DropDownList ID="ddlGrdvFrequency" runat="server"
> DataTextField="Frequency"
> DataValueField="FrequencyId"
> DataSourceID="SqlDataSourceMembershipFrequency" />
> </EditItemTemplate>
> I was looking for sth like SelectedIndex, but intellisense did not give
> me any prompt for it. I use now C# code in databound event for gridview
> to set this item selected, but ...is there a way of not using this ?
> thanks for any prompts
>
hi podi,
unfortunately the SelectedIndex cannot be set declaratively, it is a compile
error. i'm just wondering how you could know in advance with a databound
list which one to select?
an alternative would be to sort the datasource so that the one you want to
select is the first record, then it will be selected by default when the
list is databound.
i think the databound event is the correct (and best) place to achieve your
task.
i hope this helps
tim
"podi" <lukasz.podolak@.gmail.com> wrote in message
news:1159037422.462578.221520@.d34g2000cwd.googlegroups.com...
> Hi,
> I just wonder if there is a way to set a selected item in dropdown list
> which items are retreived from database without touching c# code ?
> I mean, i have in gridview, in edit mode one dropdownlist which
> selected value should be the same as a label text from normal view mode
> <EditItemTemplate>
> <asp:DropDownList ID="ddlGrdvFrequency" runat="server"
> DataTextField="Frequency"
> DataValueField="FrequencyId"
> DataSourceID="SqlDataSourceMembershipFrequency" />
> </EditItemTemplate>
> I was looking for sth like SelectedIndex, but intellisense did not give
> me any prompt for it. I use now C# code in databound event for gridview
> to set this item selected, but ...is there a way of not using this ?
> thanks for any prompts
>
Thank you for responses, it helped
Tim_Mac wrote:
> hi podi,
> unfortunately the SelectedIndex cannot be set declaratively, it is a compi
le
> error. i'm just wondering how you could know in advance with a databound
> list which one to select?
> an alternative would be to sort the datasource so that the one you want to
> select is the first record, then it will be selected by default when the
> list is databound.
> i think the databound event is the correct (and best) place to achieve you
r
> task.
> i hope this helps
> tim
>
> "podi" <lukasz.podolak@.gmail.com> wrote in message
> news:1159037422.462578.221520@.d34g2000cwd.googlegroups.com...

set selected value declaratively to dropdownlist

Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?

I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode

<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />

</EditItemTemplate>

I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any promptsHi,
You can set the selectedvalue property on the dropdownlist as follows
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddl"
DataSourceID="SqlDataSource2"
DataValueField="ProductID"
DataTextField="ProductName" SelectedValue='<%# Bind("ProductID")
%>'></asp:DropDownList>
</EditItemTemplate>

Regards,
Mohamed Mosalem

"podi" wrote:

Quote:

Originally Posted by

Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?
>
I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode
>
<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />
>
</EditItemTemplate>
>
I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts
>
>


hi podi,
unfortunately the SelectedIndex cannot be set declaratively, it is a compile
error. i'm just wondering how you could know in advance with a databound
list which one to select?
an alternative would be to sort the datasource so that the one you want to
select is the first record, then it will be selected by default when the
list is databound.

i think the databound event is the correct (and best) place to achieve your
task.
i hope this helps
tim

"podi" <lukasz.podolak@.gmail.comwrote in message
news:1159037422.462578.221520@.d34g2000cwd.googlegr oups.com...

Quote:

Originally Posted by

Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?
>
I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode
>
<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />
>
</EditItemTemplate>
>
I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts
>


Thank you for responses, it helped

Tim_Mac wrote:

Quote:

Originally Posted by

hi podi,
unfortunately the SelectedIndex cannot be set declaratively, it is a compile
error. i'm just wondering how you could know in advance with a databound
list which one to select?
an alternative would be to sort the datasource so that the one you want to
select is the first record, then it will be selected by default when the
list is databound.
>
i think the databound event is the correct (and best) place to achieve your
task.
i hope this helps
tim
>
>
>
"podi" <lukasz.podolak@.gmail.comwrote in message
news:1159037422.462578.221520@.d34g2000cwd.googlegr oups.com...

Quote:

Originally Posted by

Hi,
I just wonder if there is a way to set a selected item in dropdown list
which items are retreived from database without touching c# code ?

I mean, i have in gridview, in edit mode one dropdownlist which
selected value should be the same as a label text from normal view mode

<EditItemTemplate>
<asp:DropDownList ID="ddlGrdvFrequency" runat="server"
DataTextField="Frequency"
DataValueField="FrequencyId"
DataSourceID="SqlDataSourceMembershipFrequency" />

</EditItemTemplate>

I was looking for sth like SelectedIndex, but intellisense did not give
me any prompt for it. I use now C# code in databound event for gridview
to set this item selected, but ...is there a way of not using this ?
thanks for any prompts