Google Groepen ondersteunt geen nieuwe Usenet-berichten of -abonnementen meer. Historische content blijft zichtbaar.

How set value in ASP.NET DataGrid template column?

1 weergave
Naar het eerste ongelezen bericht

Ronald S. Cook

ongelezen,
13 okt 2003, 13:43:0213-10-2003
aan
In my ASP.NET DataGrid, I would like to set the "Selected" value of a
dropdown list item depending on a condition. While this is easy to do for,
say, a textbox, .NET doesn't seem to play as nice in a dropdownlist.

In the below I get the error
Compiler Error Message: CS0117: 'System.Web.UI.WebControls.ListItem' does
not contain a definition for 'DataBinding'

<asp:TemplateColumn HeaderText="Ver">
<HeaderStyle HorizontalAlign="Center" Width="50px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label id=lblVersion runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Version") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlVersion" runat="server">
<asp:ListItem Value="2.2">2.2</asp:ListItem>
<asp:ListItem Value="3.0" Selected="<%# IsThree(3)% >3.0</asp:ListItem>
<--- ERROR LINE
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>


public bool IsThree(int intNumber)
{
if (intNumber == 3)
return true;
else
return false;
}


Any thoughts?

Thanks,
Ron


Ignacio Machin \( .NET/ C# MVP \)

ongelezen,
13 okt 2003, 14:05:2313-10-2003
aan
Hi Ronald,

I see only one " in the selected attribute, remove it and see what happen

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ronald S. Cook" <rsc...@westinis.com> wrote in message
news:%23E992Fb...@TK2MSFTNGP10.phx.gbl...

Ronald S. Cook

ongelezen,
13 okt 2003, 14:52:0313-10-2003
aan
Nah, that's not it. Just a typo when typing up what's in my code.


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uD$QUSbkD...@TK2MSFTNGP10.phx.gbl...

Ignacio Machin \( .NET/ C# MVP \)

ongelezen,
13 okt 2003, 15:13:3713-10-2003
aan
Hi Ronald,

It seems that you cannot use DataBinding with a ListItem , if you see the
MSDN ListItem derived directly from System.Object in order to be bindable
you need to derived from WebControl or implement the IDataBindingAccessor ,
its this latter interface which define the DataBindings property ( the
source of the error)

Solution:
1- Inherit from ListItem and implement IDataBindingAccessor interface
2- Do it by code, iterate in the DropDownList.Items collection and set the
correct DropDownList.SelectedIndex

I would go for the second one.


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ronald S. Cook" <rsc...@westinis.com> wrote in message

news:%23QHlZsb...@tk2msftngp13.phx.gbl...

Steven

ongelezen,
14 okt 2003, 00:23:4314-10-2003
aan
I think your problem is in this line

<asp:Label id=lblVersion runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Version") %>'>

Your DataBinder syntax is incorrect. It should be

<asp:Label id="lblVersion" runat="server "Text='<%#
DataBinder.Eval(Container.DataItem, "Whatever") %>' />

Specifically, note the change from

DataBinder.Eval(Container, "DataItem.Version")

TO

DataBinder.Eval(Container.DataItem, "Whatever")

"Ronald S. Cook" <rsc...@westinis.com> wrote in message
news:%23E992Fb...@TK2MSFTNGP10.phx.gbl...

Ignacio Machin \( .NET/ C# MVP \)

ongelezen,
14 okt 2003, 09:40:0114-10-2003
aan
Hi Steven,

Yes, that's another error but no the one that he is getting, the thing is
that you cannot use databinding with a ListItem element.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Steven" <msgr...@berkovitz.org> wrote in message
news:uzRV2rgk...@TK2MSFTNGP09.phx.gbl...

0 nieuwe berichten