Showing posts with label selected. Show all posts
Showing posts with label selected. Show all posts

Monday, March 26, 2012

Set Dropdown List Default Text

Hi,
Is it possible to have a dropdown list that when the page is first
visited has a selected value of something like "Choose an Option". After the
user has selected an option the the user should not be able to selected the
default value an more. If this is possible could somebody show me a same in
C#.

Thanks
KennethThere are several ways to do that. One would be the SelectedIndexChanged
event. When the event occurs, check the value of the selected item. If it is
the text you don't want selected, remove that item. However, I would suggest
using a validator. The two best candidates would be the
RequiredFieldValidator and the CompareValidator.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/

"Kenneth Keeley" <kenkeeley@.hotmail.com> wrote in message
news:uFCCiVYvFHA.1436@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Is it possible to have a dropdown list that when the page is first
> visited has a selected value of something like "Choose an Option". After
> the
> user has selected an option the the user should not be able to selected
> the
> default value an more. If this is possible could somebody show me a same
> in
> C#.
> Thanks
> Kenneth

Set Dropdown List Default Text

Hi,
Is it possible to have a dropdown list that when the page is first
visited has a selected value of something like "Choose an Option". After the
user has selected an option the the user should not be able to selected the
default value an more. If this is possible could somebody show me a same in
C#.
Thanks
KennethThere are several ways to do that. One would be the SelectedIndexChanged
event. When the event occurs, check the value of the selected item. If it is
the text you don't want selected, remove that item. However, I would suggest
using a validator. The two best candidates would be the
RequiredFieldValidator and the CompareValidator.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Kenneth Keeley" <kenkeeley@.hotmail.com> wrote in message
news:uFCCiVYvFHA.1436@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Is it possible to have a dropdown list that when the page is first
> visited has a selected value of something like "Choose an Option". After
> the
> user has selected an option the the user should not be able to selected
> the
> default value an more. If this is possible could somebody show me a same
> in
> C#.
> Thanks
> Kenneth
>

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

Tuesday, March 13, 2012

Set pages encoding in code

A user can set the encoding his browser uses (In IE: View > Encoding).
I will show the page in the language the user selected (English or Japanes).
I do not want to create a seperate page for each language.
On the forms is some UserControls, with say menu's which i build in C# code, and I set the text of menu items according to the selected language.
The body of the page will be text extracted from the database in either English or Japanese.
Can one (should one?) set the page encoding in your code? I've seen that on the older asp pages, the developer set it to one value (en-jpn or sth like that...don't have access to the code as i'm typing), even though the page can be displayed in different languages, what l but sometimes a user have to go and manually set the encoding in his browser for the text to display correctly. (note : *Sometimes*)
Any suggestions what course to follow here?
It seems that with Chinese characters, on don't have problems, but Japanese is a bummer on it's ownGoogle for ResponseEncoding in ASP.NET.

BUT, I don't think that's the way it was meant to be/work. Shouldn't you be checking the language settings of the browser instead? (Tools > Options > languages)

Set selected in a BulletedList

I would like set "Selected = True" where the listitem value equals the current page.

<asp:BulletedList ID="Navigate" runat="server" DisplayMode="HyperLink">
<asp:ListItem Value="localhost">Home</asp:ListItem>
<asp:ListItem Value="localhost/link1">Link1</asp:ListItem>
<asp:ListItem Value="localhost/link2">Link2</asp:ListItem>
<asp:ListItem Value="localhost/link3">Link3</asp:ListItem>
</asp:BulletedList>

I just don't see how yet. Could someone point me in the right direction?

Thnx,

Jacco

You need to get into your codebehind and do something like this.

Navigate.SelectedValue = Page.Title


First you need to get the name of the current page. In your page directive, set
Trace="True"

Look at the list of Server Variable items in the list - PathInfo, Path Translated, ScriptName, etc - grab the one you want, and parse it to match however you're writing out your list items.

Create a variable in the page:
Dim sPage as String
Then, when the page loads (in the Page_load routine), put something like:

if not Page.IsPostback then
Dim itmAs ListItem
ForEach itmIn RadioButtonList1.Items
If itm.Text = sPageThen
itm.Selected =True
EndIf
Next
End if

Almost there.

Now I've got:

Dim itm As ListItem
Dim sDom As String = Request.ServerVariables("HTTP_HOST")
Dim sPage As String = "http://" & sDom & Request.ServerVariables("SCRIPT_NAME")
For Each itm In navigate.Items
If itm.Value = sPage Then
itm.Selected = True
End If
Next

In the debugger I see it reaches the itm.Selected only once for my four links when the Value equals sPage. But when I view the source code of the page there's still no selected item. What's missing?

Thnx,

Jacco


BTW, This does work:

If itm.Value = sPage Then
itm.Text = "|" & itm.Text & "|"
End If

Why won't it write out selected when itm.Selected is used?

Thnx,

Jacco


not sure - that code I wrote was off the top of my head (ottomh), so I really should have put a disclaimer

:)

you might try something more along the lines of:
Navigate.Items.FindByText(itm.Value).Selected = true

again - a little more off the top


I appreciate all the help. So, don't worry :-)

I've tried it and it has the same result.

The goal is to get my bulleted CSS list to display correctly. In classic ASP I did something like:

<% if urlcheck = "/web" then %> id="current"<% end if %>

Maybe I'm trying in the wrong direction.

Thnx.

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

Set selected node in Treeview control in ASP:NET 2.0 ? Anyone know this ?

Hello,

Iam using Treeview control in asp.net 2.0. But have a problem.

I use NavigateUrl BUT then viewstate is lost when clicked on a link i
the menu. And the selected node is lost.

Then i have to set the selected node manually, how can i do it ? i have
tried but without luck :(
I have posted my menu code here.

namespace DayDream.Admin.UC
{
public partial class AdminMenu : DayDreamBaseUserControl
{
public string SelectedURL;

protected void Page_Load(object sender, EventArgs e)
{
DataBind();

}

protected void PopulateNode(Object sender, TreeNodeEventArgs e)
{

// Call the appropriate method to populate a node at a
particular level.
switch (e.Node.Depth)
{
case 0:
// Populate the first-level nodes.
PopulateTopLevelNodes(e.Node);
break;
case 1:
// Populate the second-level nodes.
PopulateChildern(e.Node);
break;
default:
// Do nothing.
break;
}

}

private void PopulateTopLevelNodes(TreeNode node)
{
DayDreamBasePage basePage = new DayDreamBasePage();

for (int x = 0; x <
basePage.GetAllPages().Tables[0].Rows.Count; x++)
{
if
(basePage.GetAllPages().Tables[0].Rows[x]["ParentPageID"].ToString().Length
<= 0)
{

TreeNode TopLevel = new TreeNode();

//TopLevel.NavigateUrl =
basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString() +
"?id=" + basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.NavigateUrl =
"../../"+basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString()
+ "?id=" +
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.Text =
basePage.GetAllPages().Tables[0].Rows[x]["PageName"].ToString();
TopLevel.Value =
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();

// Add root node to TreeView
TopLevel.PopulateOnDemand = true;
TopLevel.SelectAction =
TreeNodeSelectAction.SelectExpand;
node.ChildNodes.Add(TopLevel);

}

}

}

private void PopulateChildern(TreeNode node)
{

DayDreamBasePage basePage = new DayDreamBasePage();

DataSet Childrens = new DataSet();
Childrens =
basePage.GetChildrenPages(Int32.Parse(node.Value)) ;

for (int y = 0; y < Childrens.Tables[0].Rows.Count; y++)
{

TreeNode newNode = new TreeNode();
newNode.NavigateUrl = "../../" +
Childrens.Tables[0].Rows[y]["Template"].ToString() + "?id=" +
Childrens.Tables[0].Rows[y]["PageID"].ToString();
newNode.Text =
Childrens.Tables[0].Rows[y]["PageName"].ToString();
newNode.Value =
Childrens.Tables[0].Rows[y]["PageID"].ToString();

// Set additional properties for the node.
newNode.SelectAction =
TreeNodeSelectAction.SelectExpand;

// Add the new node to the ChildNodes collection of the
parent node.
node.ChildNodes.Add(newNode);

DataSet ChildrensSub = new DataSet();
int ChildrensSubCount =
basePage.GetChildrenPages(Int32.Parse(newNode.Valu e)).Tables[0].Rows.Count;

if (ChildrensSubCount > 0)
{
PopulateChildern(newNode);
}

}
}

}
}

Thanks
JeppeOn Page_Load event you are not checking if Page isPostBack

If Not (Page.IsPostBack) {
DataBind();
}

Sandeep

"jesper_lofgren@.yahoo.se" wrote:

> Hello,
> Iam using Treeview control in asp.net 2.0. But have a problem.
> I use NavigateUrl BUT then viewstate is lost when clicked on a link i
> the menu. And the selected node is lost.
> Then i have to set the selected node manually, how can i do it ? i have
> tried but without luck :(
> I have posted my menu code here.
>
> namespace DayDream.Admin.UC
> {
> public partial class AdminMenu : DayDreamBaseUserControl
> {
> public string SelectedURL;
> protected void Page_Load(object sender, EventArgs e)
> {
> DataBind();
>
> }
> protected void PopulateNode(Object sender, TreeNodeEventArgs e)
> {
> // Call the appropriate method to populate a node at a
> particular level.
> switch (e.Node.Depth)
> {
> case 0:
> // Populate the first-level nodes.
> PopulateTopLevelNodes(e.Node);
> break;
> case 1:
> // Populate the second-level nodes.
> PopulateChildern(e.Node);
> break;
> default:
> // Do nothing.
> break;
> }
> }
>
> private void PopulateTopLevelNodes(TreeNode node)
> {
> DayDreamBasePage basePage = new DayDreamBasePage();
> for (int x = 0; x <
> basePage.GetAllPages().Tables[0].Rows.Count; x++)
> {
> if
> (basePage.GetAllPages().Tables[0].Rows[x]["ParentPageID"].ToString().Length
> <= 0)
> {
> TreeNode TopLevel = new TreeNode();
> //TopLevel.NavigateUrl =
> basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString() +
> "?id=" + basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> TopLevel.NavigateUrl =
> "../../"+basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString()
> + "?id=" +
> basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> TopLevel.Text =
> basePage.GetAllPages().Tables[0].Rows[x]["PageName"].ToString();
> TopLevel.Value =
> basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
> // Add root node to TreeView
> TopLevel.PopulateOnDemand = true;
> TopLevel.SelectAction =
> TreeNodeSelectAction.SelectExpand;
> node.ChildNodes.Add(TopLevel);
>
> }
> }
> }
>
> private void PopulateChildern(TreeNode node)
> {
> DayDreamBasePage basePage = new DayDreamBasePage();
> DataSet Childrens = new DataSet();
> Childrens =
> basePage.GetChildrenPages(Int32.Parse(node.Value)) ;
> for (int y = 0; y < Childrens.Tables[0].Rows.Count; y++)
> {
> TreeNode newNode = new TreeNode();
> newNode.NavigateUrl = "../../" +
> Childrens.Tables[0].Rows[y]["Template"].ToString() + "?id=" +
> Childrens.Tables[0].Rows[y]["PageID"].ToString();
> newNode.Text =
> Childrens.Tables[0].Rows[y]["PageName"].ToString();
> newNode.Value =
> Childrens.Tables[0].Rows[y]["PageID"].ToString();
> // Set additional properties for the node.
> newNode.SelectAction =
> TreeNodeSelectAction.SelectExpand;
> // Add the new node to the ChildNodes collection of the
> parent node.
> node.ChildNodes.Add(newNode);
> DataSet ChildrensSub = new DataSet();
> int ChildrensSubCount =
> basePage.GetChildrenPages(Int32.Parse(newNode.Valu e)).Tables[0].Rows.Count;
> if (ChildrensSubCount > 0)
> {
> PopulateChildern(newNode);
> }
> }
> }
>
> }
> }
>
> Thanks
> Jeppe
>

set selected value on a droplist

need help with trying to set selected value on a droplist.
-- tried vCaptainID as integer and string , no luck
-- tried it in pre render and also after droplist is created , no luck
========= error ======================
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error line 392 :
Line 390: vCaptainID =5 '<=test value which exists in droplist
Line 391: Dim ctrlCaptain as DropDownList =
Eventform.FindControl("IDCaptain")
Line 392: ctrlCaptain.SelectedIndex =
ctrlCaptain.Items.IndexOf(ctrlCaptain.Items.FindByValue(vCaptainID ))My guess is that the FindControl isn't finding "IDCaptain" and ctrlCaptain
is null...
if IDCaptain is embedded inside another control it won't be found via
Page.FindControl()
you need to use parentcontrol.FindControl()
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"TJS" <nospam@.here.com> wrote in message
news:OThMzkOJFHA.1304@.TK2MSFTNGP09.phx.gbl...
> need help with trying to set selected value on a droplist.
> -- tried vCaptainID as integer and string , no luck
> -- tried it in pre render and also after droplist is created , no luck
> ========= error ======================
> Exception Details: System.NullReferenceException: Object reference not
set
> to an instance of an object.
> Source Error line 392 :
> Line 390: vCaptainID =5 '<=test value which exists in droplist
> Line 391: Dim ctrlCaptain as DropDownList =
> Eventform.FindControl("IDCaptain")
> Line 392: ctrlCaptain.SelectedIndex =
> ctrlCaptain.Items.IndexOf(ctrlCaptain.Items.FindByValue(vCaptainID ))
>
>
the eventform is the parentcontrol, but I was able to produce the desired
effect using "OnItemCreated "
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:utY9PtQJFHA.572@.tk2msftngp13.phx.gbl...
> My guess is that the FindControl isn't finding "IDCaptain" and ctrlCaptain
> is null...
> if IDCaptain is embedded inside another control it won't be found via
> Page.FindControl()
> you need to use parentcontrol.FindControl()
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
> "TJS" <nospam@.here.com> wrote in message
> news:OThMzkOJFHA.1304@.TK2MSFTNGP09.phx.gbl...
> set
>

set selected value on a droplist

need help with trying to set selected value on a droplist.
-- tried vCaptainID as integer and string , no luck
-- tried it in pre render and also after droplist is created , no luck

========= error ======================
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error line 392 :

Line 390: vCaptainID =5 '<=test value which exists in droplist
Line 391: Dim ctrlCaptain as DropDownList =
Eventform.FindControl("IDCaptain")
Line 392: ctrlCaptain.SelectedIndex =
ctrlCaptain.Items.IndexOf(ctrlCaptain.Items.FindBy Value(vCaptainID ))My guess is that the FindControl isn't finding "IDCaptain" and ctrlCaptain
is null...

if IDCaptain is embedded inside another control it won't be found via
Page.FindControl()

you need to use parentcontrol.FindControl()

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"TJS" <nospam@.here.com> wrote in message
news:OThMzkOJFHA.1304@.TK2MSFTNGP09.phx.gbl...
> need help with trying to set selected value on a droplist.
> -- tried vCaptainID as integer and string , no luck
> -- tried it in pre render and also after droplist is created , no luck
> ========= error ======================
> Exception Details: System.NullReferenceException: Object reference not
set
> to an instance of an object.
> Source Error line 392 :
> Line 390: vCaptainID =5 '<=test value which exists in droplist
> Line 391: Dim ctrlCaptain as DropDownList =
> Eventform.FindControl("IDCaptain")
> Line 392: ctrlCaptain.SelectedIndex =
> ctrlCaptain.Items.IndexOf(ctrlCaptain.Items.FindBy Value(vCaptainID ))
the eventform is the parentcontrol, but I was able to produce the desired
effect using "OnItemCreated "

"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:utY9PtQJFHA.572@.tk2msftngp13.phx.gbl...
> My guess is that the FindControl isn't finding "IDCaptain" and ctrlCaptain
> is null...
> if IDCaptain is embedded inside another control it won't be found via
> Page.FindControl()
> you need to use parentcontrol.FindControl()
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
> "TJS" <nospam@.here.com> wrote in message
> news:OThMzkOJFHA.1304@.TK2MSFTNGP09.phx.gbl...
>> need help with trying to set selected value on a droplist.
>> -- tried vCaptainID as integer and string , no luck
>> -- tried it in pre render and also after droplist is created , no luck
>>
>> ========= error ======================
>> Exception Details: System.NullReferenceException: Object reference not
> set
>> to an instance of an object.
>>
>> Source Error line 392 :
>>
>> Line 390: vCaptainID =5 '<=test value which exists in droplist
>> Line 391: Dim ctrlCaptain as DropDownList =
>> Eventform.FindControl("IDCaptain")
>> Line 392: ctrlCaptain.SelectedIndex =
>> ctrlCaptain.Items.IndexOf(ctrlCaptain.Items.FindBy Value(vCaptainID ))
>>
>>
>>