DataList
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngfreeforall' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Jim Davis
Am trying to fill a DropDownList within the Edit Template of a DataList. Is
there any reason I shouldn't have access to the control or be able to find
the control in code. The following errors occure with the attached code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found where
an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList = CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM Category",
myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

Reply to this message...
 
    
Alex Lowe
Jim,

Since you didn't put the DataList code, I have to ask.....did you set
the ID of the DropDownList to "Category"?

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 2:59 PM
To: aspngfreeforall
Subject: [aspngfreeforall] DataList

Am trying to fill a DropDownList within the Edit Template of a DataList.
Is there any reason I shouldn't have access to the control or be able to
find the control in code. The following errors occure with the attached
code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found
where an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID
FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
Category", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Scott Watermasysk (VIP)
You aren't going to be able to find the dropdown list directly inside an
Edit Template. Not sure the proper lingo for why...but here is how to get
around it.

<asp:DropDownList id="Name" datasource="<%# GetThisData() %>" DataTextField
= "JobType" DataValueField = "ID" runat="server"/>

Then create a simple method that returns your datareader( ..etc)

public SqlDataReader GetThisData()
{
    //Get SqlDataReader
}

Then when you need to retrieve the value from your update/edit method:

void Update_Click(Object sender, DataListCommandEventArgs e)
{
int myID = Convert.ToInt32(((DropDownList)(e.Item.FindControl
("Name"))).SelectedItem.Value);
    //more processing
}

HTH,
Scott

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:59 PM
To: aspngfreeforall
Subject: [aspngfreeforall] DataList

Am trying to fill a DropDownList within the Edit Template of a DataList. Is
there any reason I shouldn't have access to the control or be able to find
the control in code. The following errors occure with the attached code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found where
an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList = CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
Category",
myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Jim Davis
It seems to me (logically, no .NET expertise implied) that I don't have
access to Category DropDownList because it is not being passed to the
DataListCommandEventArgs during the editItem Sub because it's part of
EditItemTemplate and not the ItemTemplate within the datalist. This of
course could be wrong, but that was my thinking.

Here is all the code.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Runat="Server">
Sub Page_Load( s As Object, e As EventArgs )
If Not isPostBack Then
BindData
End If
End Sub

Sub BindData
Dim myConnection As SqlConnection
Dim myCommand As SQLCommand
myConnection = New SqlConnection(
ConfigurationSettings.AppSettings("MyConn") )
myCommand = New SqlCommand( "Select * from pcExpItems order by Name",
myConnection )
myConnection.Open()
myDataList.DataSource = myCommand.ExecuteReader()
myDataList.DataBind()
myConnection.Close()
End Sub

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
BindData
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList = CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM pcExpCategory",
myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
    'MyCategorydd.Items.FindByValue(myCompnentID).Selected = True
    'myDataList.DataKeys.Item( e.Item.ItemIndex )

End Sub

Sub cancelEdit( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = - 1
BindData
End Sub

Sub deleteItem( s As Object, e As DataListCommandEventArgs )
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim sqlString As String
myConnection = New SqlConnection(
ConfigurationSettings.AppSettings("MyConn") )
sqlString = "Delete Authors Where ID=@ID"
myCommand = New SqlCommand( sqlString, myConnection )
myCommand.Parameters.Add( New SQLParameter( "@ID", SqlDbType.Int, 11 ))
myCommand.Parameters( "@ID" ).Value = myDataList.DataKeys.Item(
e.Item.ItemIndex )
myConnection.Open()
myCommand.ExecuteNonQuery
myDataList.DataBind()
myConnection.Close()
myDataList.EditItemIndex = - 1
BindData
End Sub

Sub updateItem( s As Object, e As DataListCommandEventArgs )
Dim myConnection As SQLConnection
Dim myCommand As SQLCommand
Dim sqlString As String
myConnection = New SQLConnection(
ConfigurationSettings.AppSettings("MyConn") )
sqlString = "Update pcExpItems Set Name=@Name, Cost=@Cost,
Retail=@Retail, SKU=@SKU Where ID=@ID"
myCommand = New SQLCommand( sqlString, myConnection )

myCommand.Parameters.Add( New SQLParameter( "@Name", SqlDbType.VarChar,
5000 ))
myCommand.Parameters( "@Name" ).Value = cTYPE( e.Item.FindControl(
"Name" ), textBox ).Text

myCommand.Parameters.Add( New SQLParameter( "@Cost", SqlDbType.Money,
8 ))
myCommand.Parameters( "@Cost" ).Value = cTYPE( e.Item.FindControl(
"Cost" ), textBox ).Text

myCommand.Parameters.Add( New SQLParameter( "@Retail", SqlDbType.Money,
8 ))
    myCommand.Parameters( "@Retail" ).Value = cTYPE( e.Item.FindControl(
"Retail" ), textBox ).Text

myCommand.Parameters.Add( New SQLParameter( "@SKU", SqlDbType.Varchar,
100 ))
    myCommand.Parameters( "@SKU" ).Value = cTYPE( e.Item.FindControl( "SKU" ),
textBox ).Text

    myCommand.Parameters.Add( New SQLParameter( "@ID", SqlDbType.VarChar, 11 ))
myCommand.Parameters( "@ID" ).Value = myDataList.DataKeys.Item(
e.Item.ItemIndex )
myConnection.Open()
myCommand.ExecuteNonQuery
myDataList.DataBind()
myConnection.Close()
myDataList.EditItemIndex = - 1
BindData
End Sub
</Script>
<HTML><head>
<link rel=stylesheet type="text/css" href="../css/main.css" title="main">
<title>PC-Xpress</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<asp:Table runat="server" GridLines="both" BorderWidth="0px">
<asp:TableRow>
<asp:TableCell colspan="2">
<pagecomponent:banner runat="server" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow >
<asp:TableCell Width="125" VerticalAlign="Top" HorizontalAlign="Left">
<pagecomponent:menu runat="server" />
</asp:TableCell>
<asp:TableCell width="500" VerticalAlign="Top" HorizontalAlign="Left">
<form Runat="Server">

<asp:DataList
id="myDataList"
cellpadding="3"
cellspacing="0"
gridlines="both"
RepeatColumns="1"
RepeatDirection="Vertical"
DataKeyField="ID"
OnEditCommand="editItem"
OnDeleteCommand="deleteItem"
OnUpdateCommand="updateItem"
OnCancelCommand="cancelEdit"
Runat="Server">
<ItemTemplate>
<asp:LinkButton
Text="Edit"
CommandName="edit"
Runat="Server"/>
<%# Container.DataItem( "Name" )%>
</ItemTemplate>
<EditItemTemplate>
<b>Item Name:</b>
<br><asp:TextBox
         width="350px"
id="Name"
text='<%# Container.DataItem( "Name" ) %>'
Runat="Server"/>
<p>
<b>Category:</b>
<br><asp:DropDownList id="Category" runat="server" />
<p>

<b>Cost:</b> <asp:TextBox
width="50px"
id="Cost"
text='<%# Container.DataItem( "Cost" ) %>'
Runat="Server"/>
<p>
<b>Retail:</b> <asp:TextBox
width="50px"
id="Retail"
text='<%# Container.DataItem( "Retail" ) %>'
Runat="Server"/>
<p>
<b>SKU:</b> <asp:TextBox
width="75px"
id="SKU"
text='<%# Container.DataItem( "SKU" ) %>'
Runat="Server"/>
<p>
<asp:Button
Text="Update"
CommandName="update"
Runat="Server"/>
<asp:Button
Text="Delete"
CommandName="delete"
Runat="Server"/>
<asp:Button
Text="Cancel"
CommandName="cancel"
Runat="Server"/>
</EditItemTemplate>
</asp:DataList>
</form>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell colspan="2">
<pagecomponent:footer runat="server" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</body>
</html>

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 5:16 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Jim,

Since you didn't put the DataList code, I have to ask.....did you set
the ID of the DropDownList to "Category"?

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 2:59 PM
To: aspngfreeforall
Subject: [aspngfreeforall] DataList

Am trying to fill a DropDownList within the Edit Template of a DataList.
Is there any reason I shouldn't have access to the control or be able to
find the control in code. The following errors occure with the attached
code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found
where an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID
FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
Category", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Alex Lowe
Scott is right. In addition to being able to set the DataSource, etc. in
the DropDownList declaration, you can also do this in code - in the
OnItemDataBound event. You can use code similar to the code found in the
DataGrid_ItemDataBound event on
(http://aspalliance.com/aldotnet/examples/datagrideditddlvb.txt).

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Scott Watermasysk [mailto:Click here to reveal e-mail address]

Sent: Thursday, December 20, 2001 3:24 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

You aren't going to be able to find the dropdown list directly inside an
Edit Template. Not sure the proper lingo for why...but here is how to
get around it.

<asp:DropDownList id="Name" datasource="<%# GetThisData() %>"
DataTextField = "JobType" DataValueField = "ID" runat="server"/>

Then create a simple method that returns your datareader( ..etc)

public SqlDataReader GetThisData()
{
    //Get SqlDataReader
}

Then when you need to retrieve the value from your update/edit method:

void Update_Click(Object sender, DataListCommandEventArgs e)
{
int myID = Convert.ToInt32(((DropDownList)(e.Item.FindControl
("Name"))).SelectedItem.Value);
    //more processing
}

HTH,
Scott

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:59 PM
To: aspngfreeforall
Subject: [aspngfreeforall] DataList

Am trying to fill a DropDownList within the Edit Template of a DataList.
Is there any reason I shouldn't have access to the control or be able to
find the control in code. The following errors occure with the attached
code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found
where an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID
FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
Category", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address =
| YOUR ID http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Jim Davis
Would this be the correct or semi correct version? This doesn't seem to
execute (the DD is still blank).

Public Sub OnItemDataBound( s As Object, e As DataListItemEventArgs )
    Dim itemType As ListItemType = e.Item.ItemType
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    Dim Category As DropDownList = CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM pcExpCategory",
myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
    'MyCategorydd.Items.FindByValue(myCompnentID).Selected = True
    'myDataList.DataKeys.Item( e.Item.ItemIndex )

End Sub

jimd

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 5:31 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Scott is right. In addition to being able to set the DataSource, etc. in
the DropDownList declaration, you can also do this in code - in the
OnItemDataBound event. You can use code similar to the code found in the
DataGrid_ItemDataBound event on
(http://aspalliance.com/aldotnet/examples/datagrideditddlvb.txt).

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Scott Watermasysk [mailto:Click here to reveal e-mail address]

Sent: Thursday, December 20, 2001 3:24 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

You aren't going to be able to find the dropdown list directly inside an
Edit Template. Not sure the proper lingo for why...but here is how to
get around it.

<asp:DropDownList id="Name" datasource="<%# GetThisData() %>"
DataTextField = "JobType" DataValueField = "ID" runat="server"/>

Then create a simple method that returns your datareader( ..etc)

public SqlDataReader GetThisData()
{
    //Get SqlDataReader
}

Then when you need to retrieve the value from your update/edit method:

void Update_Click(Object sender, DataListCommandEventArgs e)
{
int myID = Convert.ToInt32(((DropDownList)(e.Item.FindControl
("Name"))).SelectedItem.Value);
    //more processing
}

HTH,
Scott

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:59 PM
To: aspngfreeforall
Subject: [aspngfreeforall] DataList

Am trying to fill a DropDownList within the Edit Template of a DataList.
Is there any reason I shouldn't have access to the control or be able to
find the control in code. The following errors occure with the attached
code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found
where an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID
FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
Category", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address =
| YOUR ID http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Alex Lowe
You will want wrap the logic after the first line with:

If (itemType = ListItemType.EditItem) Then

End If

And you will need a DropDownList declared such as this:

<edititemtemplate>
<asp:dropdownlist id="Category" runat="server"/>
</edititemtemplate>

But yes, that looks correct.

Hth,

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:52 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Would this be the correct or semi correct version? This doesn't seem to
execute (the DD is still blank).

Public Sub OnItemDataBound( s As Object, e As DataListItemEventArgs )
    Dim itemType As ListItemType = e.Item.ItemType
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
pcExpCategory", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
    'MyCategorydd.Items.FindByValue(myCompnentID).Selected = True
    'myDataList.DataKeys.Item( e.Item.ItemIndex )

End Sub

jimd

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 5:31 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Scott is right. In addition to being able to set the DataSource, etc. in
the DropDownList declaration, you can also do this in code - in the
OnItemDataBound event. You can use code similar to the code found in the
DataGrid_ItemDataBound event on
(http://aspalliance.com/aldotnet/examples/datagrideditddlvb.txt).

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Scott Watermasysk [mailto:Click here to reveal e-mail address]

Sent: Thursday, December 20, 2001 3:24 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

You aren't going to be able to find the dropdown list directly inside an
Edit Template. Not sure the proper lingo for why...but here is how to
get around it.

<asp:DropDownList id="Name" datasource="<%# GetThisData() %>"
DataTextField = "JobType" DataValueField = "ID" runat="server"/>

Then create a simple method that returns your datareader( ..etc)

public SqlDataReader GetThisData()
{
    //Get SqlDataReader
}

Then when you need to retrieve the value from your update/edit method:

void Update_Click(Object sender, DataListCommandEventArgs e)
{
int myID = Convert.ToInt32(((DropDownList)(e.Item.FindControl
("Name"))).SelectedItem.Value);
    //more processing
}

HTH,
Scott

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:59 PM
To: aspngfreeforall
Subject: [aspngfreeforall] DataList

Am trying to fill a DropDownList within the Edit Template of a DataList.
Is there any reason I shouldn't have access to the control or be able to
find the control in code. The following errors occure with the attached
code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found
where an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID
FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
Category", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address =
| YOUR ID http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Jim Davis
Alex,

I dont think the event is firing at all, I don't see any Values for my
response.writes or in the DDList.
Is there a list of DataList events somewhere I can reference?

Thanks,

jimd

Sub OnItemDataBound( s As Object, e As DataListItemEventArgs )
Dim itemType As ListItemType = e.Item.ItemType
Response.write("Write Something")
If (itemType = ListItemType.EditItem) Then
Response.write("Write Something Else")
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    Dim Category As DropDownList = CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM pcExpCategory",
myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
End If
End Sub

<EditItemTemplate>
<b>Item Name:</b>
<br><asp:TextBox
         width="350px"
id="Name"
text='<%# Container.DataItem( "Name" ) %>'
Runat="Server"/>
<p>
<b>Category:</b>
<br><asp:DropDownList
     id="Category"
     runat="server"/>
<p>

<b>Cost:</b> <asp:TextBox
width="50px"
id="Cost"
text='<%# Container.DataItem( "Cost" ) %>'
Runat="Server"/>
<p>
<b>Retail:</b> <asp:TextBox
width="50px"
id="Retail"
text='<%# Container.DataItem( "Retail" ) %>'
Runat="Server"/>
<p>
<b>SKU:</b> <asp:TextBox
width="75px"
id="SKU"
text='<%# Container.DataItem( "SKU" ) %>'
Runat="Server"/>
<p>
<asp:Button
Text="Update"
CommandName="update"
Runat="Server"/>
<asp:Button
Text="Delete"
CommandName="delete"
Runat="Server"/>
<asp:Button
Text="Cancel"
CommandName="cancel"
Runat="Server"/>
</EditItemTemplate>

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 5:58 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

You will want wrap the logic after the first line with:

If (itemType = ListItemType.EditItem) Then

End If

And you will need a DropDownList declared such as this:

<edititemtemplate>
<asp:dropdownlist id="Category" runat="server"/>
</edititemtemplate>

But yes, that looks correct.

Hth,

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:52 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Would this be the correct or semi correct version? This doesn't seem to
execute (the DD is still blank).

Public Sub OnItemDataBound( s As Object, e As DataListItemEventArgs )
    Dim itemType As ListItemType = e.Item.ItemType
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
pcExpCategory", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
    'MyCategorydd.Items.FindByValue(myCompnentID).Selected = True
    'myDataList.DataKeys.Item( e.Item.ItemIndex )

End Sub

jimd

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 5:31 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Scott is right. In addition to being able to set the DataSource, etc. in
the DropDownList declaration, you can also do this in code - in the
OnItemDataBound event. You can use code similar to the code found in the
DataGrid_ItemDataBound event on
(http://aspalliance.com/aldotnet/examples/datagrideditddlvb.txt).

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Scott Watermasysk [mailto:Click here to reveal e-mail address]

Sent: Thursday, December 20, 2001 3:24 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

You aren't going to be able to find the dropdown list directly inside an
Edit Template. Not sure the proper lingo for why...but here is how to
get around it.

<asp:DropDownList id="Name" datasource="<%# GetThisData() %>"
DataTextField = "JobType" DataValueField = "ID" runat="server"/>

Then create a simple method that returns your datareader( ..etc)

public SqlDataReader GetThisData()
{
    //Get SqlDataReader
}

Then when you need to retrieve the value from your update/edit method:

void Update_Click(Object sender, DataListCommandEventArgs e)
{
int myID = Convert.ToInt32(((DropDownList)(e.Item.FindControl
("Name"))).SelectedItem.Value);
    //more processing
}

HTH,
Scott

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:59 PM
To: aspngfreeforall
Subject: [aspngfreeforall] DataList

Am trying to fill a DropDownList within the Edit Template of a DataList.
Is there any reason I shouldn't have access to the control or be able to
find the control in code. The following errors occure with the attached
code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found
where an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID
FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
Category", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address =
| YOUR ID http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Alex Lowe
Jim,

Are you wiring up the OnItemDataBoudn in you DataList? Something similar
to this....

<asp:DataList id="DataList1" runat="server"
OnItemDataBound="OnItemDataBound" />

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 4:14 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Alex,

I dont think the event is firing at all, I don't see any Values for my
response.writes or in the DDList. Is there a list of DataList events
somewhere I can reference?

Thanks,

jimd

Sub OnItemDataBound( s As Object, e As DataListItemEventArgs )
Dim itemType As ListItemType = e.Item.ItemType
Response.write("Write Something")
If (itemType = ListItemType.EditItem) Then
Response.write("Write Something Else")
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
pcExpCategory", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
End If
End Sub

<EditItemTemplate>
<b>Item Name:</b>
<br><asp:TextBox
         width="350px"
id="Name"
text='<%# Container.DataItem( "Name" ) %>'
Runat="Server"/>
<p>
<b>Category:</b>
<br><asp:DropDownList
     id="Category"
     runat="server"/>
<p>

<b>Cost:</b> <asp:TextBox
width="50px"
id="Cost"
text='<%# Container.DataItem( "Cost" ) %>'
Runat="Server"/>
<p>
<b>Retail:</b> <asp:TextBox
width="50px"
id="Retail"
text='<%# Container.DataItem( "Retail" ) %>'
Runat="Server"/>
<p>
<b>SKU:</b> <asp:TextBox
width="75px"
id="SKU"
text='<%# Container.DataItem( "SKU" ) %>'
Runat="Server"/>
<p>
<asp:Button
Text="Update"
CommandName="update"
Runat="Server"/>
<asp:Button
Text="Delete"
CommandName="delete"
Runat="Server"/>
<asp:Button
Text="Cancel"
CommandName="cancel"
Runat="Server"/>
</EditItemTemplate>

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 5:58 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

You will want wrap the logic after the first line with:

If (itemType = ListItemType.EditItem) Then

End If

And you will need a DropDownList declared such as this:

<edititemtemplate>
<asp:dropdownlist id="Category" runat="server"/> </edititemtemplate>

But yes, that looks correct.

Hth,

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:52 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Would this be the correct or semi correct version? This doesn't seem to
execute (the DD is still blank).

Public Sub OnItemDataBound( s As Object, e As DataListItemEventArgs )
    Dim itemType As ListItemType = e.Item.ItemType
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
pcExpCategory", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
    'MyCategorydd.Items.FindByValue(myCompnentID).Selected = True
    'myDataList.DataKeys.Item( e.Item.ItemIndex )

End Sub

jimd

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 5:31 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

Scott is right. In addition to being able to set the DataSource, etc. in
the DropDownList declaration, you can also do this in code - in the
OnItemDataBound event. You can use code similar to the code found in the
DataGrid_ItemDataBound event on
(http://aspalliance.com/aldotnet/examples/datagrideditddlvb.txt).

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Scott Watermasysk [mailto:Click here to reveal e-mail address]

Sent: Thursday, December 20, 2001 3:24 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: DataList

You aren't going to be able to find the dropdown list directly inside an
Edit Template. Not sure the proper lingo for why...but here is how to
get around it.

<asp:DropDownList id="Name" datasource="<%# GetThisData() %>"
DataTextField = "JobType" DataValueField = "ID" runat="server"/>

Then create a simple method that returns your datareader( ..etc)

public SqlDataReader GetThisData()
{
    //Get SqlDataReader
}

Then when you need to retrieve the value from your update/edit method:

void Update_Click(Object sender, DataListCommandEventArgs e)
{
int myID = Convert.ToInt32(((DropDownList)(e.Item.FindControl
("Name"))).SelectedItem.Value);
    //more processing
}

HTH,
Scott

-----Original Message-----
From: Jim Davis [mailto:Click here to reveal e-mail address]
Sent: Thursday, December 20, 2001 3:59 PM
To: aspngfreeforall
Subject: [aspngfreeforall] DataList

Am trying to fill a DropDownList within the Edit Template of a DataList.
Is there any reason I shouldn't have access to the control or be able to
find the control in code. The following errors occure with the attached
code:

--Error--
Value null was found where an instance of an object was required.
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.NullReferenceException: Value null was found
where an instance of an object was required.

Source Error:

Line 33:     myCommand = New SqlCommand( "Select Distinct Name, ID
FROM
pcExpCategory", myConnection )
Line 34:     myConnection.Open()
Line 35:     Category.DataSource = myCommand.ExecuteReader()
Line 36:     Category.DataTextField = "Name"
Line 37:     Category.DataValueField = "ID"
--Error--

Sub editItem( s As Object, e As DataListCommandEventArgs )
myDataList.EditItemIndex = e.Item.ItemIndex
    Dim MyConnection AS SQLConnection
    Dim MyCommand AS SQLCommand
    'Dim Category AS DropDownList
    Dim Category As DropDownList =
CType(e.Item.FindControl("Category"),
DropDownList)
    myConnection = New
SQLConnection(ConfigurationSettings.AppSettings("MyConn"))
    myCommand = New SqlCommand( "Select Distinct Name, ID FROM
Category", myConnection )
    myConnection.Open()
    Category.DataSource = myCommand.ExecuteReader()
    Category.DataTextField = "Name"
    Category.DataValueField = "ID"
    Category.DataBind()
    myConnection.Close()
BindData
End Sub

Thanks,

jim davis
web services
hy-tech computer systems, inc.

1840 boy scout drive
fort myers | florida 33907
941-278-4111 ext.113 | 941.278.4691 fax
Click here to reveal e-mail address | www.e-hytech.com

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

Reply to this message...
 
    
Edward Diaz
In your code-behind, you can create a function using the datareader (the code can easily be converted to use SQL server):

'-------------------------------START DROPDOWN LIST----------------------
Public Function dropdown (ByVal tableName as String) AS OleDb.OleDBdataReader

response.write("function dropdown is in effect ")

dim ConnectionString AS String="Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("\db\transferdb.mdb")

'get records from the generic table
Dim CommandString as String = "Select * from " + tableName

'create the command object and set its
'command string and connection
Dim command As New OleDb.OleDbCommand()

try

'create and open the connection object
Dim connection AS New Oledb.OleDBConnection(ConnectionString)

connection.open()

command.CommandText = commandString
command.Connection = connection

response.write("The table in use is: " + tablename)

'create the DataReader and return it
Return command.executereader(commandbehavior.closeconnection)

catch ex as exception
response.write(ex.message)

end try

end function

'------------------------------End DROPDOWN LIST--------------------------

then in your dropdown list tag you would reference it like this:

<asp:DropDownList runat="server" Id="ddl1" DataSource=<%# DropDown("tabletopassthroughthefunction")%> DataTextField="yourtext" DataValueField="yourvaluefield" SelectedValue=<%# DataBinder.Eval(Container.DataItem, "fieldtocomparetoanothertable'sfield") %> Width='200' />

Hope I helped,
Kittrick

--------------------------------
From: Edward Diaz
Reply to this message...
 
 
System.ComponentModel.Container
System.Configuration.ConfigurationSettings
System.Convert
System.Data.OleDb.OleDbCommand
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataReader
System.Data.SqlDbType
System.EventArgs
System.NullReferenceException
System.Web.UI.DataBinder
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.DataGrid
System.Web.UI.WebControls.DataList
System.Web.UI.WebControls.DataListCommandEventArgs
System.Web.UI.WebControls.DataListItemEventArgs
System.Web.UI.WebControls.DropDownList
System.Web.UI.WebControls.GridLines
System.Web.UI.WebControls.HorizontalAlign
System.Web.UI.WebControls.LinkButton
System.Web.UI.WebControls.ListItemType
System.Web.UI.WebControls.RepeatDirection
System.Web.UI.WebControls.TableCell
System.Web.UI.WebControls.TableRow
System.Web.UI.WebControls.TextBox
System.Web.UI.WebControls.VerticalAlign
System.Windows.Forms.DataGrid
System.Windows.Forms.TextBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com