Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2006, 11:16 AM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datalist

Hi All,

I have a datalist with some questions True/False. I add edit, update and cancel buttons so the user can modify his/her answers.

The problem is the following: I hit the edit button goes and selects first radiobutton value(true)always. I try to wirte a code for the datalist Ondatabound...but seems no to work at all.

How do I program the radiobutton to select whatever I have in DB.

<asp:RadioButtonList id="ddlNew" runat="server">
  <asp:ListItem Value="1">Yes</asp:ListItem>
  <asp:ListItem Value="0">No</asp:ListItem>
</asp:RadioButtonList>

Thanks.
 
Old August 31st, 2006, 11:27 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

1. Don't cross post.
2. Is it a radio button problem or a dropdownlist problem? You said radiobutton in your post then show a dropdownlist in code??

"The one language all programmers understand is profanity."
 
Old August 31st, 2006, 11:32 AM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sorry.. I mean

<asp:RadioButtonList id="rbNew" runat="server">
    <asp:ListItem Value="1">Yes</asp:ListItem>
    <asp:ListItem Value="0">No</asp:ListItem> </asp:RadioButtonList>
 
Old August 31st, 2006, 12:06 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This is what I do inside of editable datagrids

<asp:DropDownList ID="ddl" Runat="server" SelectedIndex="<%#iValue%>" DataValueField="value" DataTextField="text" DataSource="<%#datatable%>">
</asp:DropDownList>

What this means to you, when the method that handles your OnEditCommand is fired, you should populate a datatable with values from a database (In your case it would look something like this)

Value Text
0 No
1 Yes

Your selectedIndex will either be 0 or 1 (this isn't necessariliy the VALUE) so you would set up a program logic that counts looping through the records in the datatable, when it finds the value the corrosponds in the datatable, that will be your selectedindex.

For this to work correctly, the above dataset needs to be stored in a Datatable declared as PUBLIC (in this example the datatable should be named datatable) you will need to loop through the values in this datatable and compare the values stored in the datatable to the value stored in the database and increment the value iValue on each pass. When a match is found exit the loop, the value iValue will have the correct selectedIndex (iValue also needs to be declared as public).

This will set everything up so the default values of your list match your database.

"The one language all programmers understand is profanity."
 
Old September 1st, 2006, 01:35 PM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for replying...

Do you have any code sample? I'm kind of lost when you say to create a datatable inside the editcommand.





 
Old September 1st, 2006, 01:49 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No no. The OnEditCommand of a datagrid points to a sub routine in your code behind file, that is where you create the datatable.

So essentially you are creating public variables in your code behind, when you click the edit button the sub routine executes and those values then become populated and then are shared with your radio button.

"The one language all programmers understand is profanity."
 
Old September 1st, 2006, 01:55 PM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But I'm using a datalist...is that matter

 
Old September 1st, 2006, 02:06 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No, sorry for the confusion; datagrids and datalists both use the OnEditCommand, it should work the same for a datalist as it does for a datagrid.

"The one language all programmers understand is profanity."
 
Old September 1st, 2006, 02:06 PM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 How do I do this "..you will need to loop through the values in this datatable and compare the values stored in the datatable to the value stored in the database and increment the value iValue on each pass... "

Loop throught the table? I'm sorry I'm just a beginner.

 
Old September 1st, 2006, 02:10 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

for each Row in the datatable
  if [value from the database] = [current value of the row] then exit for
  iValue += 1
Next

This code obviously won't compile, its just pseudo-code, but you get the idea.




"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
DataList pbyrum ASP.NET 2.0 Basics 2 December 3rd, 2009 04:01 PM
Datalist inside datalist amit.jagtap ASP.NET 2.0 Professional 1 September 4th, 2007 05:03 AM
DataList in DataList acko ASP.NET 1.0 and 1.1 Professional 3 July 9th, 2004 05:18 PM
about datalist bvrao VS.NET 2002/2003 0 December 24th, 2003 06:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.