473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Urgent help with ItemTemplate (datagrid) - databound DropDownList

I have an itemtemplate in a datagrid. I'm trying to set it's value based on
data. Having no trouble with the textbox. But, how do I do the same thing
for a dropdownlist????

<ItemTemplate>
<asp:DropDownList id="ddlYesNo" runat="server" >
<asp:ListItem Value="-">-</asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>
<asp:TextBox id="txtComments" runat="server" Width="168px"
Text='<%# DataBinder.Eval(Container.DataItem, "Comments") %>'></asp:TextBox>
</ItemTemplate>
As you can see the TextBox works great! But, how do I set the
DropDownList's value to a similar data field?

Thanks!
Nov 18 '05 #1
6 1749
You can either go in the ItemDataBound event and do

dim ddl as dropdownlist = ctype(e.item.findControl("ddlYesNo"),
dropdownlist)
ddl.selectedIndex = 1

or you can do something like

<asp:listItem value="yes" selected='<%# DataBinder.Eval(Container.DataItem,
"yesNo") = "yes"%>'>
<asp:listItem value="yes" selected='<%# DataBinder.Eval(Container.DataItem,
"yesNo") = "no"%>'>

or something like that.

Karl

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have an itemtemplate in a datagrid. I'm trying to set it's value based on data. Having no trouble with the textbox. But, how do I do the same thing for a dropdownlist????

<ItemTemplate>
<asp:DropDownList id="ddlYesNo" runat="server" >
<asp:ListItem Value="-">-</asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>
<asp:TextBox id="txtComments" runat="server" Width="168px" Text='<%# DataBinder.Eval(Container.DataItem, "Comments") %>'></asp:TextBox> </ItemTemplate>
As you can see the TextBox works great! But, how do I set the
DropDownList's value to a similar data field?

Thanks!

Nov 18 '05 #2
I just tried doing one item. I tried this:

<asp:DropDownList id="ddlYesNo" runat="server" >
<asp:ListItem Value="-">-</asp:ListItem>
<asp:ListItem Value="Yes" Selected='<%#
DataBinder.Eval(Container.DataItem, "Results") = "Yes"
%>'>Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>

But I got this error: Compiler Error Message: BC30676: 'DataBinding' is not
an event of 'System.Web.UI.WebControls.ListItem'.

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:u5*************@TK2MSFTNGP09.phx.gbl...
You can either go in the ItemDataBound event and do

dim ddl as dropdownlist = ctype(e.item.findControl("ddlYesNo"),
dropdownlist)
ddl.selectedIndex = 1

or you can do something like

<asp:listItem value="yes" selected='<%# DataBinder.Eval(Container.DataItem, "yesNo") = "yes"%>'>
<asp:listItem value="yes" selected='<%# DataBinder.Eval(Container.DataItem, "yesNo") = "no"%>'>

or something like that.

Karl

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have an itemtemplate in a datagrid. I'm trying to set it's value
based on
data. Having no trouble with the textbox. But, how do I do the same

thing
for a dropdownlist????

<ItemTemplate>
<asp:DropDownList id="ddlYesNo" runat="server" >
<asp:ListItem Value="-">-</asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>
<asp:TextBox id="txtComments" runat="server"

Width="168px"
Text='<%# DataBinder.Eval(Container.DataItem, "Comments")

%>'></asp:TextBox>
</ItemTemplate>
As you can see the TextBox works great! But, how do I set the
DropDownList's value to a similar data field?

Thanks!


Nov 18 '05 #3
Oh well, I was wrong.

You'll need to do it the other way:

Private Sub x_ItenDataBound(ByVal source As Object, ByVal e As
RepeaterItemEventArgs) Handles x.ItemDataBound
'get a reference to the DLL here and via e.Item.FindControl("ddlYesNo")
and you can access the row via e.Item.DataIem which will allow you to apply
the logic you need to figure out which item to select
End Sub

Karl
"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I just tried doing one item. I tried this:

<asp:DropDownList id="ddlYesNo" runat="server" >
<asp:ListItem Value="-">-</asp:ListItem>
<asp:ListItem Value="Yes" Selected='<%#
DataBinder.Eval(Container.DataItem, "Results") = "Yes"
%>'>Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>

But I got this error: Compiler Error Message: BC30676: 'DataBinding' is not an event of 'System.Web.UI.WebControls.ListItem'.

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:u5*************@TK2MSFTNGP09.phx.gbl...
You can either go in the ItemDataBound event and do

dim ddl as dropdownlist = ctype(e.item.findControl("ddlYesNo"),
dropdownlist)
ddl.selectedIndex = 1

or you can do something like

<asp:listItem value="yes" selected='<%#

DataBinder.Eval(Container.DataItem,
"yesNo") = "yes"%>'>
<asp:listItem value="yes" selected='<%#

DataBinder.Eval(Container.DataItem,
"yesNo") = "no"%>'>

or something like that.

Karl

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have an itemtemplate in a datagrid. I'm trying to set it's value

based
on
data. Having no trouble with the textbox. But, how do I do the same

thing
for a dropdownlist????

<ItemTemplate>
<asp:DropDownList id="ddlYesNo" runat="server" >
<asp:ListItem Value="-">-</asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>
<asp:TextBox id="txtComments" runat="server"

Width="168px"
Text='<%# DataBinder.Eval(Container.DataItem, "Comments")

%>'></asp:TextBox>
</ItemTemplate>
As you can see the TextBox works great! But, how do I set the
DropDownList's value to a similar data field?

Thanks!



Nov 18 '05 #4
How do I know the data value of the "current" field if I do it this way?

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:uz**************@TK2MSFTNGP15.phx.gbl...
Oh well, I was wrong.

You'll need to do it the other way:

Private Sub x_ItenDataBound(ByVal source As Object, ByVal e As
RepeaterItemEventArgs) Handles x.ItemDataBound
'get a reference to the DLL here and via e.Item.FindControl("ddlYesNo")
and you can access the row via e.Item.DataIem which will allow you to apply the logic you need to figure out which item to select
End Sub

Karl
"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I just tried doing one item. I tried this:

<asp:DropDownList id="ddlYesNo" runat="server" >
<asp:ListItem Value="-">-</asp:ListItem>
<asp:ListItem Value="Yes" Selected='<%#
DataBinder.Eval(Container.DataItem, "Results") = "Yes"
%>'>Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>

But I got this error: Compiler Error Message: BC30676: 'DataBinding' is

not
an event of 'System.Web.UI.WebControls.ListItem'.

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:u5*************@TK2MSFTNGP09.phx.gbl...
You can either go in the ItemDataBound event and do

dim ddl as dropdownlist = ctype(e.item.findControl("ddlYesNo"),
dropdownlist)
ddl.selectedIndex = 1

or you can do something like

<asp:listItem value="yes" selected='<%#

DataBinder.Eval(Container.DataItem,
"yesNo") = "yes"%>'>
<asp:listItem value="yes" selected='<%#

DataBinder.Eval(Container.DataItem,
"yesNo") = "no"%>'>

or something like that.

Karl

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> I have an itemtemplate in a datagrid. I'm trying to set it's value

based
on
> data. Having no trouble with the textbox. But, how do I do the same thing
> for a dropdownlist????
>
> <ItemTemplate>
> <asp:DropDownList id="ddlYesNo" runat="server" >
> <asp:ListItem Value="-">-</asp:ListItem>
> <asp:ListItem Value="Yes">Yes</asp:ListItem>
> <asp:ListItem Value="No">No</asp:ListItem>
> </asp:DropDownList>
> <asp:TextBox id="txtComments" runat="server"
Width="168px"
> Text='<%# DataBinder.Eval(Container.DataItem, "Comments")
%>'></asp:TextBox>
> </ItemTemplate>
>
>
> As you can see the TextBox works great! But, how do I set the
> DropDownList's value to a similar data field?
>
> Thanks!
>
>



Nov 18 '05 #5
As I said, you have access to e.Item.DataItem. which is an object, but can
be cast to a DataRowView (assuming you are binding form a
datatable/dataset/dataview)

dim dv as DataRowView = ctype(e.item.DataItem, DataRowView)
if cstr(dv("yesNo")) = "yes" then
...
I think it's a datarowview anyways...

Karl

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How do I know the data value of the "current" field if I do it this way?

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:uz**************@TK2MSFTNGP15.phx.gbl...
Oh well, I was wrong.

You'll need to do it the other way:

Private Sub x_ItenDataBound(ByVal source As Object, ByVal e As
RepeaterItemEventArgs) Handles x.ItemDataBound
'get a reference to the DLL here and via e.Item.FindControl("ddlYesNo")
and you can access the row via e.Item.DataIem which will allow you to

apply
the logic you need to figure out which item to select
End Sub

Karl
"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I just tried doing one item. I tried this:

<asp:DropDownList id="ddlYesNo" runat="server" >
<asp:ListItem Value="-">-</asp:ListItem>
<asp:ListItem Value="Yes" Selected='<%#
DataBinder.Eval(Container.DataItem, "Results") = "Yes"
%>'>Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:DropDownList>

But I got this error: Compiler Error Message: BC30676: 'DataBinding' is
not
an event of 'System.Web.UI.WebControls.ListItem'.

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote

in message news:u5*************@TK2MSFTNGP09.phx.gbl...
> You can either go in the ItemDataBound event and do
>
> dim ddl as dropdownlist = ctype(e.item.findControl("ddlYesNo"),
> dropdownlist)
> ddl.selectedIndex = 1
>
> or you can do something like
>
> <asp:listItem value="yes" selected='<%#
DataBinder.Eval(Container.DataItem,
> "yesNo") = "yes"%>'>
> <asp:listItem value="yes" selected='<%#
DataBinder.Eval(Container.DataItem,
> "yesNo") = "no"%>'>
>
> or something like that.
>
> Karl
>
> "VB Programmer" <Do*****************@jEmail.com> wrote in message
> news:%2****************@tk2msftngp13.phx.gbl...
> > I have an itemtemplate in a datagrid. I'm trying to set it's
value based
> on
> > data. Having no trouble with the textbox. But, how do I do the

same > thing
> > for a dropdownlist????
> >
> > <ItemTemplate>
> > <asp:DropDownList id="ddlYesNo" runat="server" >
> > <asp:ListItem Value="-">-</asp:ListItem>
> > <asp:ListItem Value="Yes">Yes</asp:ListItem>
> > <asp:ListItem Value="No">No</asp:ListItem>
> > </asp:DropDownList>
> > <asp:TextBox id="txtComments" runat="server"
> Width="168px"
> > Text='<%# DataBinder.Eval(Container.DataItem, "Comments")
> %>'></asp:TextBox>
> > </ItemTemplate>
> >
> >
> > As you can see the TextBox works great! But, how do I set the
> > DropDownList's value to a similar data field?
> >
> > Thanks!
> >
> >
>
>



Nov 18 '05 #6
It works!!!! Karl for President!!!!!

THANKS!!!!!

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:OL*************@TK2MSFTNGP10.phx.gbl...
As I said, you have access to e.Item.DataItem. which is an object, but can be cast to a DataRowView (assuming you are binding form a
datatable/dataset/dataview)

dim dv as DataRowView = ctype(e.item.DataItem, DataRowView)
if cstr(dv("yesNo")) = "yes" then
...
I think it's a datarowview anyways...

Karl

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How do I know the data value of the "current" field if I do it this way?

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:uz**************@TK2MSFTNGP15.phx.gbl...
Oh well, I was wrong.

You'll need to do it the other way:

Private Sub x_ItenDataBound(ByVal source As Object, ByVal e As
RepeaterItemEventArgs) Handles x.ItemDataBound
'get a reference to the DLL here and via e.Item.FindControl("ddlYesNo") and you can access the row via e.Item.DataIem which will allow you to apply
the logic you need to figure out which item to select
End Sub

Karl
"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> I just tried doing one item. I tried this:
>
> <asp:DropDownList id="ddlYesNo" runat="server" >
> <asp:ListItem Value="-">-</asp:ListItem>
> <asp:ListItem Value="Yes" Selected='<%#
> DataBinder.Eval(Container.DataItem, "Results") = "Yes"
> %>'>Yes</asp:ListItem>
> <asp:ListItem Value="No">No</asp:ListItem>
> </asp:DropDownList>
>
> But I got this error: Compiler Error Message: BC30676:
'DataBinding' is not
> an event of 'System.Web.UI.WebControls.ListItem'.
>
> "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in
> message news:u5*************@TK2MSFTNGP09.phx.gbl...
> > You can either go in the ItemDataBound event and do
> >
> > dim ddl as dropdownlist = ctype(e.item.findControl("ddlYesNo"),
> > dropdownlist)
> > ddl.selectedIndex = 1
> >
> > or you can do something like
> >
> > <asp:listItem value="yes" selected='<%#
> DataBinder.Eval(Container.DataItem,
> > "yesNo") = "yes"%>'>
> > <asp:listItem value="yes" selected='<%#
> DataBinder.Eval(Container.DataItem,
> > "yesNo") = "no"%>'>
> >
> > or something like that.
> >
> > Karl
> >
> > "VB Programmer" <Do*****************@jEmail.com> wrote in message
> > news:%2****************@tk2msftngp13.phx.gbl...
> > > I have an itemtemplate in a datagrid. I'm trying to set it's

value > based
> > on
> > > data. Having no trouble with the textbox. But, how do I do the

same
> > thing
> > > for a dropdownlist????
> > >
> > > <ItemTemplate>
> > > <asp:DropDownList id="ddlYesNo" runat="server" > > <asp:ListItem Value="-">-</asp:ListItem>
> > > <asp:ListItem Value="Yes">Yes</asp:ListItem>
> > > <asp:ListItem Value="No">No</asp:ListItem>
> > > </asp:DropDownList>
> > > <asp:TextBox id="txtComments" runat="server"
> > Width="168px"
> > > Text='<%# DataBinder.Eval(Container.DataItem, "Comments")
> > %>'></asp:TextBox>
> > > </ItemTemplate>
> > >
> > >
> > > As you can see the TextBox works great! But, how do I set the
> > > DropDownList's value to a similar data field?
> > >
> > > Thanks!
> > >
> > >
> >
> >
>
>



Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Deepa | last post by:
Hi Am doing a web app which has a datagrid with template columns. One of the columns has dropdowns for each row. I also have the EditCommandColumn. The problem am facing is I just see the last...
1
by: Muhammad Usman | last post by:
Respected Assistant I have table in a database named "student" having fields like name of student,Roll No and Status.The status is one of them absent,present or leave.The name and rollno field...
4
by: News | last post by:
I have a page with many controls. Among these controls there is a table which is a datagrid with nested repeater inside. My problem is that I can not use DataGridCommandEventArgs to get datagrid...
8
by: David | last post by:
This is something I had never seen before. On an aspx page, upon pressing a link button for which I have an event handler in the code behind, the screen shows nothing but a line that says "true"...
1
by: hansiman | last post by:
OK. Now I got around to getting values out of the datagrid in the OnUpdateCommand rutine: Datagrid: <asp:BoundColumn Visible="False" DataField="EmployeeID" HeaderText="EmployeeID" /> <asp:...
1
by: I am Sam | last post by:
I need to be able to delete a record/row from a database table. I am using a DataGrid which is not sending the row index key properly to the event in the codebehind. When I set a break point and...
9
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be...
9
by: Jakob Lithner | last post by:
1) I have a DataGridView with edit capability. But in some columns I want to limit the input with a DropDownList. There is no inbuilt column for DropDownLists so I intended to add one myself. I...
0
by: Dan | last post by:
Hi, I have a detailsview with two fields: in editmode, one is a textbox and the other is a dropdownlist. i want to update both fields using the detailsview. My problem: when clicking on the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.