Showing posts with label dropdownlist. Show all posts
Showing posts with label dropdownlist. Show all posts

Saturday, March 31, 2012

the best way display data from dropdownlist?

OK..i have a field called - areaID,

i would like to make it to display areaNAME instead of ID, so a human can understand.

What i have done:

1. Converted that field into template;

2. For Edit mode - i made drop down list where a user can choose areaName instead of areaID, though areaID is bounded to the field.

3. For Item mode - ? my question:

i don't want to make the same dropdown list display, it looks not appropriate, - i would like to have 'label' like component to display my areaName on areaID field, how to do it?

I could probably create some function or stored procedure to return areaName, and as a parameter use areaID, but i don't want to complecate matters too much...

I know it had been done 100 times...but not by me...

anyone can give a hint?

thanks for your help!!

I'm not sure why you wouldn't just return the areaname in the query/sp that fills the grid, and use a Label or Literal in your ItemTemplate. After all, the value for that row doesn't really come from the dropdownlist; it comes from the datasource for the parent control.


Hi Peter, I think I have the same issue in that I would like to display descriptive names for domain data in the ItemTemplate, but in order to bind a dropdown in the EditTempate I also need the ID field. Are you suggesting having both the IDand description fields available in the datasource and then binding ItemTemplate label to the description field and the EditTemplate dropdown to the ID field? Sorry if I'm slow, I'm new to .NET in general


Thanks,

- Ben


I am not sure you are asking the right question, because it sounds like you are using a GridView, or other data control. But dropdowns have two properties, DataTextField and dataValueField where you set the field names to display in a drop-down.

That's not what I'm getting at; In a FormView I would like to show a label control in the "view" mode (ItemTemplate) and switch to a dropdown control in the "edit" mode (EditTemplate). My data table currently stores only the ID/foreign key of the domain table as it has been normalized. Now, this arrangement works perfectly with the dropdown as it is populated with the domain dataset and then it's selected row is bound to the ID field in my formview's dataset. Fine.

But in "view" mode I want to add alabel control that shows the user-friendly descriptive text from the domain table instead of a cryptic ID. As stated by the original poster, I could always write a function to "lookup" the domain description using the ID as a key but I'm thinking that's not the in the spirit of the declarative syntax and it's not efficient.

What I think was proposed was to join to the domain table in my source query and get the domain description and have it available along with the ID so I can bind to either one as needed. Was that the idea?


Yes, that's it. Just join on the ID field and pull the name as part of your datasource.


Thanks!

Wednesday, March 28, 2012

The case of the crazy reseting dropdowns :-( Please help!

Hi everyone,

I keep getting a problem with dropdownlist controls. It sounds really stupid,
but my app is screwed as long as this keeps happening.

It seems to spontaneously happen and then I cant fix it without rebuilding
the whole page from scratch! Not Fun. :-(

So whats happening is I have my dropdowns on the page. The user comes along
and selects an option, but when the user submits the page,. its as if nothing
was changed.
The dropdowns all reset themselves to the default values. No modified value
reaches the server so its not just a view state thing (I think).

So basically, my dropdowns just dont work. Bear in mind, that these were
all working perfectly before. I then do some trivial work to the page - adding
controls and the like, and the whole thing just buggers up!

Can anyone think whats happening here? What would cause dropdown controls
to just stop sending their values and reset themselves?

If anyone at all has even the stupidist suggestion I would be so grateful
if you could tell me cos this is getting really serious. Its supposed to
be live now!

:-(

Thanks to anyone who can help

SimonSimon,
Do your dropdown controls have their AutoPostback property set to "true"?
This is required if you want a change by the user to cause a postback
and fire the SelectedIndexChanged event where you can handle the event.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

"Simon Harvey" wrote:

> Hi everyone,
> I keep getting a problem with dropdownlist controls. It sounds really stupid,
> but my app is screwed as long as this keeps happening.
> It seems to spontaneously happen and then I cant fix it without rebuilding
> the whole page from scratch! Not Fun. :-(
> So whats happening is I have my dropdowns on the page. The user comes along
> and selects an option, but when the user submits the page,. its as if nothing
> was changed.
> The dropdowns all reset themselves to the default values. No modified value
> reaches the server so its not just a view state thing (I think).
> So basically, my dropdowns just dont work. Bear in mind, that these were
> all working perfectly before. I then do some trivial work to the page - adding
> controls and the like, and the whole thing just buggers up!
> Can anyone think whats happening here? What would cause dropdown controls
> to just stop sending their values and reset themselves?
> If anyone at all has even the stupidist suggestion I would be so grateful
> if you could tell me cos this is getting really serious. Its supposed to
> be live now!
> :-(
> Thanks to anyone who can help
> Simon
>
After the user submits the form, how are you getting the values from
the drop downs?

After the form is submitted does yourDropDown.SelectedValue = "" - or
the default value?

Have you tried Request.Form("youDropDown")? Does that still equal ""?

Can you reply back with some code for us?

Jeremy Reid
http://blackstaronline.net/hgtit
are you filling up your combobox each time the page loads? did you use "if
(!Page.IsPostBack)" is not, you should, it's probably your problem.

I hope it helps

ThunderMusic

"Simon Harvey" <nothanks@dotnet.itags.org.hotmail.com> wrote in message
news:94a1890869bf8c8038d5030666f@dotnet.itags.org.news.microsoft.co m...
> Hi everyone,
> I keep getting a problem with dropdownlist controls. It sounds really
> stupid, but my app is screwed as long as this keeps happening.
> It seems to spontaneously happen and then I cant fix it without rebuilding
> the whole page from scratch! Not Fun. :-(
> So whats happening is I have my dropdowns on the page. The user comes
> along and selects an option, but when the user submits the page,. its as
> if nothing was changed.
> The dropdowns all reset themselves to the default values. No modified
> value reaches the server so its not just a view state thing (I think).
> So basically, my dropdowns just dont work. Bear in mind, that these were
> all working perfectly before. I then do some trivial work to the page -
> adding controls and the like, and the whole thing just buggers up!
> Can anyone think whats happening here? What would cause dropdown controls
> to just stop sending their values and reset themselves?
> If anyone at all has even the stupidist suggestion I would be so grateful
> if you could tell me cos this is getting really serious. Its supposed to
> be live now!
> :-(
> Thanks to anyone who can help
> Simon

The case of the crazy reseting dropdowns :-( Please help!

Hi everyone,
I keep getting a problem with dropdownlist controls. It sounds really stupid
,
but my app is screwed as long as this keeps happening.
It seems to spontaneously happen and then I cant fix it without rebuilding
the whole page from scratch! Not Fun. :-(
So whats happening is I have my dropdowns on the page. The user comes along
and selects an option, but when the user submits the page,. its as if nothin
g
was changed.
The dropdowns all reset themselves to the default values. No modified value
reaches the server so its not just a view state thing (I think).
So basically, my dropdowns just dont work. Bear in mind, that these were
all working perfectly before. I then do some trivial work to the page - addi
ng
controls and the like, and the whole thing just buggers up!
Can anyone think whats happening here? What would cause dropdown controls
to just stop sending their values and reset themselves?
If anyone at all has even the stupidist suggestion I would be so grateful
if you could tell me cos this is getting really serious. Its supposed to
be live now!
:-(
Thanks to anyone who can help
SimonSimon,
Do your dropdown controls have their AutoPostback property set to "true"?
This is required if you want a change by the user to cause a postback
and fire the SelectedIndexChanged event where you can handle the event.
Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Simon Harvey" wrote:

> Hi everyone,
> I keep getting a problem with dropdownlist controls. It sounds really stup
id,
> but my app is screwed as long as this keeps happening.
> It seems to spontaneously happen and then I cant fix it without rebuilding
> the whole page from scratch! Not Fun. :-(
> So whats happening is I have my dropdowns on the page. The user comes alon
g
> and selects an option, but when the user submits the page,. its as if noth
ing
> was changed.
> The dropdowns all reset themselves to the default values. No modified valu
e
> reaches the server so its not just a view state thing (I think).
> So basically, my dropdowns just dont work. Bear in mind, that these were
> all working perfectly before. I then do some trivial work to the page - ad
ding
> controls and the like, and the whole thing just buggers up!
> Can anyone think whats happening here? What would cause dropdown controls
> to just stop sending their values and reset themselves?
> If anyone at all has even the stupidist suggestion I would be so grateful
> if you could tell me cos this is getting really serious. Its supposed to
> be live now!
> :-(
> Thanks to anyone who can help
> Simon
>
>
After the user submits the form, how are you getting the values from
the drop downs?
After the form is submitted does yourDropDown.SelectedValue = "" - or
the default value?
Have you tried Request.Form("youDropDown")? Does that still equal ""?
Can you reply back with some code for us?
Jeremy Reid
http://blackstaronline.net/hgtit
are you filling up your combobox each time the page loads? did you use "if
(!Page.IsPostBack)" is not, you should, it's probably your problem.
I hope it helps
ThunderMusic
"Simon Harvey" <nothanks@dotnet.itags.org.hotmail.com> wrote in message
news:94a1890869bf8c8038d5030666f@dotnet.itags.org.news.microsoft.com...
> Hi everyone,
> I keep getting a problem with dropdownlist controls. It sounds really
> stupid, but my app is screwed as long as this keeps happening.
> It seems to spontaneously happen and then I cant fix it without rebuilding
> the whole page from scratch! Not Fun. :-(
> So whats happening is I have my dropdowns on the page. The user comes
> along and selects an option, but when the user submits the page,. its as
> if nothing was changed.
> The dropdowns all reset themselves to the default values. No modified
> value reaches the server so its not just a view state thing (I think).
> So basically, my dropdowns just dont work. Bear in mind, that these were
> all working perfectly before. I then do some trivial work to the page -
> adding controls and the like, and the whole thing just buggers up!
> Can anyone think whats happening here? What would cause dropdown controls
> to just stop sending their values and reset themselves?
> If anyone at all has even the stupidist suggestion I would be so grateful
> if you could tell me cos this is getting really serious. Its supposed to
> be live now!
> :-(
> Thanks to anyone who can help
> Simon
>

Saturday, March 24, 2012

The directory name is invalid

In VS2005 I drop a button and a dropdownlist on a web form.
When I try to change the name of these (i.e. from Button1 to btnEdit)
in the Properties panel, I get a message popping up saying "The
directory name is invalid." and it won't let me change the
name.
Any Ideas?Actually I had a problem like that once with the Beta program, I closed the
solution, open again and I was able to rename it, what version of the VS2005
are you running and did you try that?
Cheers
Al
"jhcorey@.yahoo.com" wrote:

> In VS2005 I drop a button and a dropdownlist on a web form.
> When I try to change the name of these (i.e. from Button1 to btnEdit)
> in the Properties panel, I get a message popping up saying "The
> directory name is invalid." and it won't let me change the
> name.
> Any Ideas?
>

The directory name is invalid

In VS2005 I drop a button and a dropdownlist on a web form.
When I try to change the name of these (i.e. from Button1 to btnEdit)
in the Properties panel, I get a message popping up saying "The
directory name is invalid." and it won't let me change the
name.
Any Ideas?Actually I had a problem like that once with the Beta program, I closed the
solution, open again and I was able to rename it, what version of the VS2005
are you running and did you try that?

Cheers
Al

"jhcorey@.yahoo.com" wrote:

> In VS2005 I drop a button and a dropdownlist on a web form.
> When I try to change the name of these (i.e. from Button1 to btnEdit)
> in the Properties panel, I get a message popping up saying "The
> directory name is invalid." and it won't let me change the
> name.
> Any Ideas?
>

Thursday, March 22, 2012

The first intem in a DropDownList is vanishing!

The first intem in a DropDownList is vanishing!

My code to load a DropDownList is shown below. Yet when I load the
page after a postback there is no zeroth item present.

lstManager.Items.Clear();

lstManager.DataSource = _dsData.Tables["manager"].DefaultView;
lstManager.DataValueField = "ManagerID";
lstManager.DataTextField = "Name";
lstManager.DataBind();

lstManager.Items.Insert(0, new ListItem("none", "0"));

There's nothing special about the control definition:

<asp:DropDownList ID="lstManager" runat="server" Height="20px"
Width="250px" />

What's going on here?

This was the old code I replaced. Why does the old code (below) work
and why is my new code (above) broke?

lstManager.Items.Clear();

ListItem li = new ListItem("none","0");
lstManager.Items.Add(li);

foreach (DataRow drManager in _dsData.Tables["manager"].Rows)
{
ListItem liManager = new ListItem((string)drManager["Name"],
((int)drManager["ManagerID"]).ToString());
lstManager.Items.Add(liManager);
}I had this one a while back; turns out I was using simple properties
on a Master Page that required a DataBind() call to bind them. When
it was called, it was also rebinding the content page, which loses the
manually added items.

I recall this issue also happened with an ASCX file on the page, or if
you call a generic DataBind() any time after the addition of
ListItems, etc.

Dunc
http://www.fluidfoundation.com
On 1 Jun, 15:24, mark4asp <mark4...@.gmail.comwrote:

Quote:

Originally Posted by

The first intem in a DropDownList is vanishing!
>
My code to load a DropDownList is shown below. Yet when I load the
page after a postback there is no zeroth item present.
>
lstManager.Items.Clear();
>
lstManager.DataSource = _dsData.Tables["manager"].DefaultView;
lstManager.DataValueField = "ManagerID";
lstManager.DataTextField = "Name";
lstManager.DataBind();
>
lstManager.Items.Insert(0, new ListItem("none", "0"));
>
There's nothing special about the control definition:
>
<asp:DropDownList ID="lstManager" runat="server" Height="20px"
Width="250px" />
>
What's going on here?
>
This was the old code I replaced. Why does the old code (below) work
and why is my new code (above) broke?
>
lstManager.Items.Clear();
>
ListItem li = new ListItem("none","0");
lstManager.Items.Add(li);
>
foreach (DataRow drManager in _dsData.Tables["manager"].Rows)
{
ListItem liManager = new ListItem((string)drManager["Name"],
((int)drManager["ManagerID"]).ToString());
lstManager.Items.Add(liManager);
}


On 1 Jun, 16:30, Dunc <duncan.we...@.gmail.comwrote:

Quote:

Originally Posted by

I had this one a while back; turns out I was using simple properties
on a Master Page that required a DataBind() call to bind them. When
it was called, it was also rebinding the content page, which loses the
manually added items.
>
I recall this issue also happened with an ASCX file on the page, or if
you call a generic DataBind() any time after the addition of
ListItems, etc.
>
Dunchttp://www.fluidfoundation.com
>
On 1 Jun, 15:24, mark4asp <mark4...@.gmail.comwrote:
>
>
>

Quote:

Originally Posted by

The first intem in a DropDownList is vanishing!


>

Quote:

Originally Posted by

My code to load a DropDownList is shown below. Yet when I load the
page after a postback there is no zeroth item present.


>

Quote:

Originally Posted by

lstManager.Items.Clear();


>

Quote:

Originally Posted by

lstManager.DataSource = _dsData.Tables["manager"].DefaultView;
lstManager.DataValueField = "ManagerID";
lstManager.DataTextField = "Name";
lstManager.DataBind();


>

Quote:

Originally Posted by

lstManager.Items.Insert(0, new ListItem("none", "0"));


>

Quote:

Originally Posted by

There's nothing special about the control definition:


>

Quote:

Originally Posted by

<asp:DropDownList ID="lstManager" runat="server" Height="20px"
Width="250px" />


>

Quote:

Originally Posted by

What's going on here?


>

Quote:

Originally Posted by

This was the old code I replaced. Why does the old code (below) work
and why is my new code (above) broke?


>

Quote:

Originally Posted by

lstManager.Items.Clear();


>

Quote:

Originally Posted by

ListItem li = new ListItem("none","0");
lstManager.Items.Add(li);


>

Quote:

Originally Posted by

foreach (DataRow drManager in _dsData.Tables["manager"].Rows)
{
ListItem liManager = new ListItem((string)drManager["Name"],
((int)drManager["ManagerID"]).ToString());
lstManager.Items.Add(liManager);
}- Hide quoted text -


>
- Show quoted text -


Thanks Dunc, for sharing that with me - that scenario you described
sounds very like mine.

The first intem in a DropDownList is vanishing!

The first intem in a DropDownList is vanishing!
My code to load a DropDownList is shown below. Yet when I load the
page after a postback there is no zeroth item present.
lstManager.Items.Clear();
lstManager.DataSource = _dsData.Tables["manager"].DefaultView;
lstManager.DataValueField = "ManagerID";
lstManager.DataTextField = "Name";
lstManager.DataBind();
lstManager.Items.Insert(0, new ListItem("none", "0"));
There's nothing special about the control definition:
<asp:DropDownList ID="lstManager" runat="server" Height="20px"
Width="250px" />
What's going on here?
This was the old code I replaced. Why does the old code (below) work
and why is my new code (above) broke?
lstManager.Items.Clear();
ListItem li = new ListItem("none","0");
lstManager.Items.Add(li);
foreach (DataRow drManager in _dsData.Tables["manager"].Rows)
{
ListItem liManager = new ListItem((string)drManager["Name"],
((int)drManager["ManagerID"]).ToString());
lstManager.Items.Add(liManager);
}I had this one a while back; turns out I was using simple properties
on a Master Page that required a DataBind() call to bind them. When
it was called, it was also rebinding the content page, which loses the
manually added items.
I recall this issue also happened with an ASCX file on the page, or if
you call a generic DataBind() any time after the addition of
ListItems, etc.
Dunc
http://www.fluidfoundation.com
On 1 Jun, 15:24, mark4asp <mark4...@.gmail.com> wrote:
> The first intem in a DropDownList is vanishing!
> My code to load a DropDownList is shown below. Yet when I load the
> page after a postback there is no zeroth item present.
> lstManager.Items.Clear();
> lstManager.DataSource = _dsData.Tables["manager"].DefaultView;
> lstManager.DataValueField = "ManagerID";
> lstManager.DataTextField = "Name";
> lstManager.DataBind();
> lstManager.Items.Insert(0, new ListItem("none", "0"));
> There's nothing special about the control definition:
> <asp:DropDownList ID="lstManager" runat="server" Height="20px"
> Width="250px" />
> What's going on here?
> This was the old code I replaced. Why does the old code (below) work
> and why is my new code (above) broke?
> lstManager.Items.Clear();
> ListItem li = new ListItem("none","0");
> lstManager.Items.Add(li);
> foreach (DataRow drManager in _dsData.Tables["manager"].Rows)
> {
> ListItem liManager = new ListItem((string)drManager["Name"],
> ((int)drManager["ManagerID"]).ToString());
> lstManager.Items.Add(liManager);
> }
On 1 Jun, 16:30, Dunc <duncan.we...@.gmail.com> wrote:
> I had this one a while back; turns out I was using simple properties
> on a Master Page that required a DataBind() call to bind them. When
> it was called, it was also rebinding the content page, which loses the
> manually added items.
> I recall this issue also happened with an ASCX file on the page, or if
> you call a generic DataBind() any time after the addition of
> ListItems, etc.
> Dunchttp://www.fluidfoundation.com
> On 1 Jun, 15:24, mark4asp <mark4...@.gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -
Thanks Dunc, for sharing that with me - that scenario you described
sounds very like mine.

The first value of a dropdownlist

How can I show a value at the beginning of the dropdownlist with my
structure? This initial value isn' t in the database, for instance
'(Select)'.

<script language="VB" runat="server"
Sub Page_Load()

Dim strConnection As New
SqlConnection("Server=nou;database=market1;uid=sa;password=;")

Dim families As string = "SELECT family_Name FROM
Families;"

Dim DS1 As DataSet
Dim CommandFamilies As SqlDataAdapter

CommandFamilies = New SqlDataAdapter(families, strConnection)

DS1 = new DataSet()
CommandFamilies.Fill(DS1, "Families")

MySelect1.DataSource=
DS1.Tables("Families").DefaultView
MySelect1.DataBind()

End Sub

</script
...

<form runat="server"
<asp:dropdownlist id="MySelect1"
DataTextField="family_Name" runat="server"
class="letter1"
</asp:dropdownlist
...

--== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==--
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
--= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--not sure of the VB .net syntax, but here it is in C#

ListItem li = new ListItem();
YourDDL.Items.Add(li, 0);

put's a blank item at the beginning of your drop down list

"cesark" <cesar_casafont@.hotmail-dot-com.no-spam.invalid> wrote in message
news:400db905$1_2@.127.0.0.1...
> How can I show a value at the beginning of the dropdownlist with my
> structure? This initial value isn' t in the database, for instance
> '(Select)'.
>
> <script language="VB" runat="server">
> Sub Page_Load()
> Dim strConnection As New
> SqlConnection("Server=nou;database=market1;uid=sa;password=;")
> Dim families As string = "SELECT family_Name FROM
> Families;"
>
> Dim DS1 As DataSet
> Dim CommandFamilies As SqlDataAdapter
> CommandFamilies = New SqlDataAdapter(families, strConnection)
> DS1 = new DataSet()
> CommandFamilies.Fill(DS1, "Families")
>
> MySelect1.DataSource=
> DS1.Tables("Families").DefaultView
> MySelect1.DataBind()
>
> End Sub
> </script>
>
> ...
> <form runat="server">
> <asp:dropdownlist id="MySelect1"
> DataTextField="family_Name" runat="server"
> class="letter1">
> </asp:dropdownlist>
> ...
>
>
> --== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet
News==--
> http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
> --= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=--
I have already achieved it 8) . The right code was:

MySelect2.Items.Insert(0, "(Select a value)")
MySelect2.SelectedIndex = 0

Just before of 'MySelect2.DataBind()'

Thank you anyway :)

--== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==--
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
--= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--