473,320 Members | 2,111 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,320 software developers and data experts.

Datagrid with Yes/No Dropdownlist

I have added a dropdownlist to an editable datagrid to allow a user to select
Yes or No:

<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem,
"reports") %>' ID="lblReports"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" id="ddlReports">
<asp:ListItem value="Yes">Yes</asp:listItem>
<asp:ListItem value="No">No</asp:listItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

Works great.

My problem occurs when the user clicks the edit button. The value always
comes up to "Yes" in the dropdownlist, even if the value in the datagrid
label was "No".

How do I code it to make the value in the dropdownlist match the value in
the datagrid label before Edit was selected ?

Thanks,
Jeff
Dec 1 '05 #1
3 1777
Add a DataBinder expression for the SelectedValue. Assuming that the field
named "Reports" holds a string value of either "Yes" or "No" then:

<asp:DropDownList ID="ddlReports" Runat="server"
SelectedValue='<%# DataBinder.Eval(Container.DataItem, "reports") %>'>
<asp:ListItem value="Yes">Yes</asp:listItem>
<asp:ListItem value="No">No</asp:listItem>
</asp:DropDownList>

But if the field value can have a blank or any other value, you need to
create a condition, e.g. (C# syntax)
<asp:DropDownList ID="ddlReports" Runat="server"
SelectedValue='<%# DataBinder.Eval(Container.DataItem,
"reports").Equals("Yes")?"Yes","No" %>'>
<asp:ListItem value="Yes">Yes</asp:listItem>
<asp:ListItem value="No">No</asp:listItem>
</asp:DropDownList>
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Jeff" wrote:
I have added a dropdownlist to an editable datagrid to allow a user to select
Yes or No:

<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem,
"reports") %>' ID="lblReports"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" id="ddlReports">
<asp:ListItem value="Yes">Yes</asp:listItem>
<asp:ListItem value="No">No</asp:listItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

Works great.

My problem occurs when the user clicks the edit button. The value always
comes up to "Yes" in the dropdownlist, even if the value in the datagrid
label was "No".

How do I code it to make the value in the dropdownlist match the value in
the datagrid label before Edit was selected ?

Thanks,
Jeff

Dec 1 '05 #2
Thanks Phillip..

That did the trick... I appreciate your help.

Jeff

Dec 1 '05 #3
Jeff,

On ItemEdit event of DataGrid add this code

Dim ddlList as DropDownList
ddlList = e.Item.FindControl("ddlReports")

If Not ddlList Is Nothing Then
ddlList.selectedValue = e.Item.DataItem("ddlReports")
END If
HTH

Nilesh


"Jeff" <Je**@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
I have added a dropdownlist to an editable datagrid to allow a user to
select
Yes or No:

<ItemTemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,
"reports") %>' ID="lblReports"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" id="ddlReports">
<asp:ListItem value="Yes">Yes</asp:listItem>
<asp:ListItem value="No">No</asp:listItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

Works great.

My problem occurs when the user clicks the edit button. The value always
comes up to "Yes" in the dropdownlist, even if the value in the datagrid
label was "No".

How do I code it to make the value in the dropdownlist match the value in
the datagrid label before Edit was selected ?

Thanks,
Jeff

Dec 1 '05 #4

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

Similar topics

2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
7
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
2
by: Ben | last post by:
Hi, I'd like to have a datagrid that has a dropdownlist in the pager control for setting the page size. I can get the control into the pager inside the datagrid itemcreated event by checking for...
2
by: Shiju Poyilil | last post by:
Hello, I have a datagrid with only one row and its having 2 dropdownlists, I need to populate the secodn dropdownlist on the basis of the selection in the first dropdown. but I am not able to...
1
by: m3ckon | last post by:
Hi there, please help if you can, I'm having an issue with droponnlists in a datagrid I have a datagrid which is populated from a query .. all works fine I've added two extra columns, one...
2
by: Steve Pierce | last post by:
I am having some issues with a runtime dropdownlist in a datagrid. The issue is that I cannot get ViewState to fill the selected index of a runtime dropdown properly on postback. I do not want to...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.