Showing posts with label index. Show all posts
Showing posts with label index. Show all posts

Monday, March 26, 2012

Set dropdownlist value

I have a dropdownlist that I was setting to an index (which happened
to be the same as the value). I changed this to a character as that
is what I want to have in my database.
<asp:dropdownlist
style="border:none" id="recurrenceType"
runat="server">
<asp:listitem value="N"
>None</asp:listitem>
<asp:listitem value="M"
>Monthly</asp:listitem>
<asp:listitem value="P"
>Periodic</asp:listitem>
</asp:dropdownlist>
I was setting the value before (when the value was "0", "1" and "2").
It used to work like this:
recurrenceType.SelectedIndex = objDataReader("recurrenceType")
How would I set it with the value set to a char?
Thanks,
Tom.
Posted Via mcse.ms Premium Usenet Newsgroup Services
----
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----
http://www.mcse.msChange
recurrenceType.SelectedIndex = ...
To
recurrenceType.SelectedValue = ...
"tfs" wrote:

> I have a dropdownlist that I was setting to an index (which happened
> to be the same as the value). I changed this to a character as that
> is what I want to have in my database.
> <asp:dropdownlist
> style="border:none" id="recurrenceType"
> runat="server">
> <asp:listitem value="N"
> <asp:listitem value="M"
> <asp:listitem value="P"
> </asp:dropdownlist>
>
> I was setting the value before (when the value was "0", "1" and "2").
> It used to work like this:
> recurrenceType.SelectedIndex = objDataReader("recurrenceType")
> How would I set it with the value set to a char?
> Thanks,
> Tom.
>
> Posted Via mcse.ms Premium Usenet Newsgroup Services
> ----
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----
> http://www.mcse.ms
>
I just tried this:
recurrenceType.SelectedItem.value = "P"
The display on the screen is still "None".
Thanks,
Tom.
Posted Via mcse.ms Premium Usenet Newsgroup Services
----
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----
http://www.mcse.ms
I have tried all kinds of ways to get this to work and keep getting
strange (at least to me) results.
If I do a viewsource of the above statement (my last post):
recurrenceType.SelectedItem.value = "P"
I get the following:
<select name="recurrenceType" id="recurrenceType"
style="border:none">
<option selected="selected" value="P">None</option>
<option value="M">Monthly</option>
<option value="P">Periodic</option>
</select>
It seems to change the value, which I guess is what I am saying - but
this is how I saw it selected in one example. I am trying to get it
to move the selected="selected" to the 3rd option and it isn't doing
it.
I then tried:
recurrenceType.Items.FindByValue("P").selected = true
And got the following error:
A DropDownList cannot have multiple items selected.
Description: An unhandled exception occurred during the execution
of the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: A DropDownList
cannot have multiple items selected.
Source Error:
Line 132: </table>
Line 133:
Line 134: <form runat="server">
Line 135: <table align="center">
Line 136: <tr
valign="baseline">
This is driving me crazy.
Thanks,
Tom.
Posted Via mcse.ms Premium Usenet Newsgroup Services
----
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----
http://www.mcse.ms
The syntax should be something close to this:
recurrenceType.SelectedItem=recurrenceType.Items.FindByValue("P")
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"tfs" <tfs@.dslextreme-dot-com.no-spam.invalid> wrote in message
news:40eb0582$1_1@.mcse.ms...
> I have a dropdownlist that I was setting to an index (which happened
> to be the same as the value). I changed this to a character as that
> is what I want to have in my database.
> <asp:dropdownlist
> style="border:none" id="recurrenceType"
> runat="server">
> <asp:listitem value="N"
> <asp:listitem value="M"
> <asp:listitem value="P"
> </asp:dropdownlist>
>
> I was setting the value before (when the value was "0", "1" and "2").
> It used to work like this:
> recurrenceType.SelectedIndex = objDataReader("recurrenceType")
> How would I set it with the value set to a char?
> Thanks,
> Tom.
>
> Posted Via mcse.ms Premium Usenet Newsgroup Services
> ----
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----
> http://www.mcse.ms
I think what you are looking for is -
((ListItem)recurrenceType.Items.FindByValue("P")).Selected = true;
Bobby Ryzhy
bobby@.wendtech.net
[url]http://www.wendtech.net[/url]
On Tue, 6 Jul 2004 14:43:16 -0700, "Steve C. Orr [MVP, MCSD]"
<Steve@.Orr.net> wrote:

>The syntax should be something close to this:
>recurrenceType.SelectedItem=recurrenceType.Items.FindByValue("P")
Yes, I believe that is more precise.
"Bobby Ryzhy" <bryzhy@.hotmail.com> wrote in message
news:vt8me0l7uanmgb9iln5o7nsvbal012e867@.
4ax.com...
> I think what you are looking for is -
> ((ListItem)recurrenceType.Items.FindByValue("P")).Selected = true;
> Bobby Ryzhy
> bobby@.wendtech.net
> [url]http://www.wendtech.net[/url]
>
> On Tue, 6 Jul 2004 14:43:16 -0700, "Steve C. Orr [MVP, MCSD]"
> <Steve@.Orr.net> wrote:
>
>
SelectValue was it.
Here is what I did that works fine.
recurrenceType.SelectedValue =
objDataReader("recurrenceType")
recurrenceDisplay.text = recurrenceType.SelectedItem.text
<td nowrap>Recurrance:</td>
<td>
<asp:label id="recurrenceDisplay"
runat="server" />
<asp:dropdownlist style="visibility:hidden"
id="recurrenceType" runat="server">
<asp:listitem value="N"
>None</asp:listitem>
<asp:listitem value="M"
>Monthly</asp:listitem>
<asp:listitem value="P"
>Periodic</asp:listitem>
</asp:dropdownlist>
</td>
Thanks,
Tom
Posted Via mcse.ms Premium Usenet Newsgroup Services
----
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----
http://www.mcse.ms

Set dropdownlist value

I have a dropdownlist that I was setting to an index (which happened
to be the same as the value). I changed this to a character as that
is what I want to have in my database.

<asp:dropdownlist
style="border:none" id="recurrenceType"
runat="server">
<asp:listitem value="N"
>None</asp:listitem>
<asp:listitem value="M"
>Monthly</asp:listitem>
<asp:listitem value="P"
>Periodic</asp:listitem>
</asp:dropdownlist
I was setting the value before (when the value was "0", "1" and "2").
It used to work like this:

recurrenceType.SelectedIndex = objDataReader("recurrenceType")

How would I set it with the value set to a char?

Thanks,

Tom.

Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.comI have tried all kinds of ways to get this to work and keep getting
strange (at least to me) results.

If I do a viewsource of the above statement (my last post):

recurrenceType.SelectedItem.value = "P"

I get the following:

<select name="recurrenceType" id="recurrenceType"
style="border:none">
<option selected="selected" value="P">None</option>
<option value="M">Monthly</option>
<option value="P">Periodic</option>
</select
It seems to change the value, which I guess is what I am saying - but
this is how I saw it selected in one example. I am trying to get it
to move the selected="selected" to the 3rd option and it isn't doing
it.

I then tried:

recurrenceType.Items.FindByValue("P").selected = true

And got the following error:

A DropDownList cannot have multiple items selected.
Description: An unhandled exception occurred during the execution
of the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A DropDownList
cannot have multiple items selected.

Source Error:

Line 132: </table>
Line 133:
Line 134: <form runat="server">
Line 135: <table align="center">
Line 136: <tr
valign="baseline"
This is driving me crazy.

Thanks,

Tom.

Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.com
I just tried this:

recurrenceType.SelectedItem.value = "P"

The display on the screen is still "None".

Thanks,

Tom.

Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.com
The syntax should be something close to this:

recurrenceType.SelectedItem=recurrenceType.Items.F indByValue("P")

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

"tfs" <tfs@.dslextreme-dot-com.no-spam.invalid> wrote in message
news:40eb0582$1_1@.Usenet.com...
> I have a dropdownlist that I was setting to an index (which happened
> to be the same as the value). I changed this to a character as that
> is what I want to have in my database.
> <asp:dropdownlist
> style="border:none" id="recurrenceType"
> runat="server">
> <asp:listitem value="N"
> >None</asp:listitem>
> <asp:listitem value="M"
> >Monthly</asp:listitem>
> <asp:listitem value="P"
> >Periodic</asp:listitem>
> </asp:dropdownlist>
>
> I was setting the value before (when the value was "0", "1" and "2").
> It used to work like this:
> recurrenceType.SelectedIndex = objDataReader("recurrenceType")
> How would I set it with the value set to a char?
> Thanks,
> Tom.
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
> ------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ------------------
> http://www.usenet.com
I think what you are looking for is -
((ListItem)recurrenceType.Items.FindByValue("P")).Selected = true;

Bobby Ryzhy
bobby@.weekendtech.net
http://www.weekendtech.net

On Tue, 6 Jul 2004 14:43:16 -0700, "Steve C. Orr [MVP, MCSD]"
<Steve@.Orr.net> wrote:

>The syntax should be something close to this:
>recurrenceType.SelectedItem=recurrenceType.Items.F indByValue("P")
Yes, I believe that is more precise.

"Bobby Ryzhy" <bryzhy@.hotmail.com> wrote in message
news:vt8me0l7uanmgb9iln5o7nsvbal012e867@.4ax.com...
> I think what you are looking for is -
> ((ListItem)recurrenceType.Items.FindByValue("P")).Selected = true;
> Bobby Ryzhy
> bobby@.weekendtech.net
> http://www.weekendtech.net
>
> On Tue, 6 Jul 2004 14:43:16 -0700, "Steve C. Orr [MVP, MCSD]"
> <Steve@.Orr.net> wrote:
> >The syntax should be something close to this:
> >recurrenceType.SelectedItem=recurrenceType.Items.F indByValue("P")
SelectValue was it.

Here is what I did that works fine.

recurrenceType.SelectedValue =
objDataReader("recurrenceType")
recurrenceDisplay.text = recurrenceType.SelectedItem.text

<td nowrap align="right">Recurrance:</td>
<td>
<asp:label id="recurrenceDisplay"
runat="server" />
<asp:dropdownlist style="visibility:hidden"
id="recurrenceType" runat="server">
<asp:listitem value="N"
>None</asp:listitem>
<asp:listitem value="M"
>Monthly</asp:listitem>
<asp:listitem value="P"
>Periodic</asp:listitem>
</asp:dropdownlist>
</td
Thanks,

Tom

Posted Via Usenet.com Premium Usenet Newsgroup Services
------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
------------------
http://www.usenet.com

Saturday, March 24, 2012

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
loads, I need the focus to be on one of the textboxes called
txtUserName.

I come from a VB background, so expecting the obvious, I go to the
Page_Load event of the index.aspx page and try to write
txtUserName.SetFocus but I see there isn't a SetFocus method for the
System.Web.UI.WebControls.TextBox class.

What's the way to set the focus to a textbox on the page load in
ASP.NET?It's a client-side task. You need to call javascript focus() method on the
element you want to set focus on.

Eliyahu

"Water Cooler v2" <wtr_clr@.yahoo.com> wrote in message
news:1124274011.476683.55980@.o13g2000cwo.googlegro ups.com...
> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
you can write a function something like this and use it when u need them.

protected void SetFocus(Control controlToFocus){
string formName = GetFormName(controlToFocus);
string jsString="<script language=javascript>document." + formName +
".elements['" + controlToFocus.UniqueID + "'].focus();</script>";
if(Page.IsStartupScriptRegistered("SetFocusToSearch")==false)
Page.RegisterStartupScript("SetFocusToSearch",jsString);

Hope this helps.
--
Kannan.V
Home : http://www.kannanv.com
Blog : http://kannanv.blogspot.com
Web : http://www.DotnetLounge.net

"Any one who has never made a mistake has never tried anything new" - Einstein

"Water Cooler v2" wrote:

> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
As the last post adviced this should do the trick:-

Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javascript'>" & _
"document.getElementById('" + ctrl.ClientID & _
"').focus();</script>"

' Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript)
End Sub

Hope this helps
Patrick

*** Sent via Developersdex http://www.developersdex.com ***

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page loads, I need the focus to be on one of the textboxes called txtUserName.

I come from a VB background, so expecting the obvious, I go to the Page_Load event of the index.aspx page and try to write txtUserName.SetFocus but I see there isn't a SetFocus method for the System.Web.UI.WebControls.TextBox class.

What's the way to set the focus to a textbox on the page load in ASP.NET?take a look at this thread:

http://www.vbforums.com/showthread.php?t=316582&highlight=textbox+focus
Hi , You may use a java script

<SCRIPT LANGUAGE="JavaScript">
function setFocus()
{
document.Form1('TxtCno').focus()
}
</SCRIPT>

and call it in

<body MS_POSITIONING="GridLayout" bgColor="#003366" onload="setFocus();">


thats it it will focus the cursor on your desired field

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
loads, I need the focus to be on one of the textboxes called
txtUserName.
I come from a VB background, so expecting the obvious, I go to the
Page_Load event of the index.aspx page and try to write
txtUserName.SetFocus but I see there isn't a SetFocus method for the
System.Web.UI.WebControls.TextBox class.
What's the way to set the focus to a textbox on the page load in
ASP.NET?It's a client-side task. You need to call javascript focus() method on the
element you want to set focus on.
Eliyahu
"Water Cooler v2" <wtr_clr@.yahoo.com> wrote in message
news:1124274011.476683.55980@.o13g2000cwo.googlegroups.com...
> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
you can write a function something like this and use it when u need them.
protected void SetFocus(Control controlToFocus){
string formName = GetFormName(controlToFocus);
string jsString="<script language=javascript>document." + formName +
".elements['" + controlToFocus.UniqueID + "'].focus();</script>";
if(Page.IsStartupScriptRegistered("SetFocusToSearch")==false)
Page.RegisterStartupScript("SetFocusToSearch",jsString);
Hope this helps.
--
Kannan.V
Home : http://www.kannanv.com
Blog : http://kannanv.blogspot.com
Web : http://www.DotnetLounge.net
"Any one who has never made a mistake has never tried anything new" - Einste
in
"Water Cooler v2" wrote:

> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
As the last post adviced this should do the trick:-
Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javascript'>" & _
"document.getElementById('" + ctrl.ClientID & _
"').focus();</script>"
' Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript)
End Sub
Hope this helps
Patrick
*** Sent via Developersdex http://www.examnotes.net ***

Thursday, March 22, 2012

set index of drop downbox

Hi,

I would like to set the selected item of drop downbox to the index of an
item that will only be known at run time.

I realise that if I were to know it at design time I could write

ddlResidentialCity.SelectedIndex = 3

however what I wish to do is say

ddlResidentialCity.SelectedIndex = Set to value of item who's text value is
"martin"

what I am unsure about is how to get the index of the item I wish to use as
the selected index

any help would be appreciated.

cheers

martinH

ddlResidentalCity.Items.FindByValue("martin").Selected = True
How about this?

ddlResidentialCity.SelectedValue = "martin"

"martin" <Stuart_REMOVE_36@.yahoo.com> wrote in message news:<#N9fYmwQEHA.132@.TK2MSFTNGP09.phx.gbl>...
> Hi,
> I would like to set the selected item of drop downbox to the index of an
> item that will only be known at run time.
> I realise that if I were to know it at design time I could write
> ddlResidentialCity.SelectedIndex = 3
> however what I wish to do is say
> ddlResidentialCity.SelectedIndex = Set to value of item who's text value is
> "martin"
> what I am unsure about is how to get the index of the item I wish to use as
> the selected index
>
> any help would be appreciated.
> cheers
> martin

set index of drop downbox

Hi,
I would like to set the selected item of drop downbox to the index of an
item that will only be known at run time.
I realise that if I were to know it at design time I could write
ddlResidentialCity.SelectedIndex = 3
however what I wish to do is say
ddlResidentialCity.SelectedIndex = Set to value of item who's text value is
"martin"
what I am unsure about is how to get the index of the item I wish to use as
the selected index
any help would be appreciated.
cheers
martinHi
ddlResidentalCity.Items.FindByValue("martin").Selected = True
ddlResidentialCity.SelectedIndex = ddlResidentalCity.Items.IndexOf( ddlResid
entalCity.Items.FindByText("martin"))
How about this?
ddlResidentialCity.SelectedValue = "martin"
"martin" <Stuart_REMOVE_36@.yahoo.com> wrote in message news:<#N9fYmwQEHA.132@.TK2MSFTNGP09.p
hx.gbl>...
> Hi,
> I would like to set the selected item of drop downbox to the index of an
> item that will only be known at run time.
> I realise that if I were to know it at design time I could write
> ddlResidentialCity.SelectedIndex = 3
> however what I wish to do is say
> ddlResidentialCity.SelectedIndex = Set to value of item who's text value i
s
> "martin"
> what I am unsure about is how to get the index of the item I wish to use a
s
> the selected index
>
> any help would be appreciated.
> cheers
> martin