Setting the value of a RadioButtonList based on a value in my sql table.

Hi folks,
From a Sql database table I'm trying to display a RadioButtonList with two text values, "Buy" and "Sell". The actual numeric values in my table are 1 (Buy) or 2 (Sell). The name of the column in the table is "buy_sell".
So how do I set the SELECTED="TRUE" property in the ListItem based on the value of my buy_sell column ?

<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" OnInit="FormView1_Init">
..
..
<EditItemTemplate>
<td><asp:RadioButtonList  DataSourceID="ObjectDataSource1" DataValueField="buy_sell" DataTextField="buy_sell" ID="radioBuySell" runat="server"                   
                  OnDataBinding="radioBuySell_DataBinding">
               <asp:ListItem Value="1">Buy</asp:ListItem>
               <asp:ListItem Value="2">Sell</asp:ListItem>
         </asp:RadioButtonList>
</td>                   

    <asp:ObjectDataSource ID="ObjectDataSource1" TypeName="DataComponents" runat="server" SelectMethod="GetOrderRec" ConflictDetection="CompareAllValues">
        <SelectParameters><asp:QueryStringParameter Name="ticket" DefaultValue=0 Type="Int32" QueryStringField="ticket" /></SelectParameters>
    </asp:ObjectDataSource>


0
robertmazzo
11/30/2005 3:10:45 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
1377 Views

Similar Articles

[PageSpeed] 18

I don't like the way I resolved it, but it works. I created an
invisible label item, then programatically set the SelectedItem of my
RadioButtonList accordingly.
Shouldn't I be able to set my RadioButtonList some other way ?

<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" OnInit="FormView1_Init">
....
<EditItemTemplate>
.. . .
  <td><asp:Label ID="lblBuy_Sell"  Visible="false" runat="server" Text='<%# Eval("buy_sell") %>' /></td>
....


   protected void radioBuySell_DataBinding(object sender, EventArgs e)
    {
        Label lblBuy_Sell = (Label)FormView1.FindControl("lblBuy_Sell");
        String lcBuy_Sell = lblBuy_Sell.Text;
        RadioButtonList radBuy_Sell = (RadioButtonList)FormView1.FindControl("radioBuySell");
       
        if (lcBuy_Sell == "1")
        {   // BUY
            radBuy_Sell.SelectedIndex = 0;
        }
        else
        {   // SELL
            radBuy_Sell.SelectedIndex = 1;
        }
    }

0
robertmazzo
11/30/2005 7:02:58 PM

Another way to get the SelectedIndex (or SelectedValue) is to do the following in the FormView1:

<asp:RadioButtonList ID="IsApprovedRadioButtonList" runat="server" SelectedIndex='<%# Convert.ToInt32(Eval("buy_sell")) %>' RepeatDirection="Horizontal" >

<asp:ListItem Value="1">Sell</asp:ListItem>

<asp:ListItem Value="0">Buy</asp:ListItem>

</asp:RadioButtonList>

 

Hope this helps,

d.

0
developerJamiro
2/15/2006 4:45:00 AM
Reply:

Similar Artilces:

Getting a value from a SQL table displaying a specific page based on that value
May seem to newbie but here goes:I have a login page.  For the login I run a stored procedure with 4 return values, 0 - being valid, 1 - username exists already, 2 - username is incorrect3 - password is incorrectThis all works fine.  But from that I have the default page when the login credentials are correct.  The issue is I need to display a specific default page based on their location id from the member table which I already run a sp against for the login.  I have set up an .ascx page with a datagrid to display the results which works when I run the query for a h...

Add values to a table based on values in another table
When a record is inserted or updated records in Table1 I want a record to be inserted into table3 for each record ID that is in table2 if the table2.id does not already exist in table3. What is the best way to do this? Could this be done with a trigger? If it could how would I write such a trigger. I have never written one before and this sounds like a hand full for my first effort. Your help will be greatly appreciated. Thanks You could do it in a trigger.  They're really not hard.  It's just SQL you want to run whenever a certain action happens on your table.  Pretty st...

Set value on a Container page (aspx) based on the value of a user control (ascx)
How can i change a value on the aspx page based on the value in a user control on that page. I am using codebehind on both files. Thank you. the usercontrol should expose a public property that the container can read a value from.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ Thank you. That is not what I am trying to do. How do I change a value on the Container page based on a value on the usercontrol. For example, I have a several link buttons on the Container page. Lets say i select the first l...

RadioButtonList
I'm trying to modify a page that has a radiobuttonlist inside a form.  I want to set the selected item based on data returned from a sql query.  The Radio Button List has 2 items, Male and Female, with values equal to 0 and 1 respectively.  The sql column is of type Bit. How can I set the selected item based on the sql data?  Here's the relevant code from the page: Here's the SQL Commands that retrieves the data: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDB%>" SelectCommand="SELECT * FROM albums WHERE...

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to asp.net i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.http://www.heliosfx.com...

Setting a dropdownlist value based on a value in a Database
I have a page that allows users to create a user account. The aspx has various dropdowns that I populate by binding the dropdownlist to a dataset. OK so far? However, I also want a page where the user can edit their profile..so I need to be able to set the selected value based on what is saved in my user table and I also need to add the extra entries. Anyone know how I can do this easily. Do I need to join on my user table and my table that has all the various categories in order to get the selected value and add my other values?? Thanks, COG. For selecting the correct...

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

The value set to controls at client side donot persist for each page load, else it is again set to the default value...??
 I am trying to set date to the textbox field using javascript (Client side), the function is as follows. function From_calendarPicker(){                                var    sDPath = "../Calender.aspx";                 var    oWin = window.showModalDialog(sDPath, null, "dialogWidth:300px;dialogHeight:250px;help:0;status:0;scroll:0;center:1");  &nbs...

setting non server control values: input type="text" how to set value programmatically?
<form id="someForm" runat="server" enableviewstate="true">  <input id="manualtextbox" type="text" value="abc" name="manualtextbox" /></form> I have access to user supplied value via: string userEnteredThisInForm = Request.Params["manualtextbox"] but, how can I set the value when sending form back to browser? If it's not runat="server" then you'll have to emit javascript to set the value: document.getElementById('manualtextbox').value = '<desired value>'; add runat="sever" to the control  <input id="manualtextbox" type="text" value="abc" name="m...

Setting Values in User Control Based on Session Vars Set After Page Load
Ok ... I have a web app that includes multiple custom user controls on each page. I would like to set values in my "header" control (first one loaded on page) based on session variables I set upon user events in the parent page. For example, the user would select a value from a dropdownlist that sets a session variable, say a certain account number, and I would like that value to appear in the header control on the post back. If I put code to check for the session variable in the page load of the control, it won't show up until a subsequent postback. Basically, I need to ...

Setting the Parameter Value to the Property Value of a Web Control
I want to filter my DetailsView with a declarative parameter. In my case, I am setting the SqlDataSource's parameter values based on the value of 2 TextBox controls on the page. I have a SP that does a SELECT based on 1 of the parameters passed in (either an ID or phone number). Param Name          Value MemberID          TextBox1.Text Phone               TextBox2.Text I want to assign a default value of 'null' for b...

How to set selected value in drop down based on query value
i have a dropdownlist populated with values frm database   when i want to view or edit a particular record i populated the textbox with the needed record details same way i wan the dropdown to display the selected value as the first index received frm the query  If you palced it inside a data control , then you can bind it's selected value with a database field like this :<asp:DropDownList id=...  SelectedVale='<%# Eval("DataBaseField") %>'  .... Regards,Anas Ghanem.Note:Please Don't hesitate to click "Report Abuse" ...

Set TextBox text value to value from DataList Control
I'm sure this is a totally sad question to ask, but... I am using a DataList View to display data. I have a separate form within a LoginView that I would like to use to update a few main fields. I want to set the Text property of the TextBox in my custom edit form to the value of the corresponding field in the DataList. Is this possible? I think i get your question --> you want the text from a  textbox from the datalist to be input into a textbox within your form? try:TextBox tb = DataList1.FindControl("TextBoxIDToFind"); TextBoxOnForm.Text = tb.Text;David Ki...

how to accessing values and set values for a controls that is inside a datagrid
hi this is chandra mohan working as software engineer . here i am having problem with accessing valuse and setting values for controls inside a datagrid. actually i am having datagrid and in this grid i am having item templates of one dropdwon list and text box. i having one Reset link buttion out side the grid(that is in the form) by clicking this Reset Link buttion it should invokes the javascript function and in that function it should set all textboxes of datagrid to  .. txtActionVal.readOnly = true;   txtActionVal.Value ="";and dropdownlist to  dropdownlist...

how to set the cascading dropdownextendar value to the value of dropdownlist control
i have a cascading drop down extendar inside gridview , a dropdownlist control , a link button. i want to set the  value of dropdownextendar to the value of dropdown when i click the link button . <EditItemTemplate> <asp:DropDownList ID="ProvinceDDL" runat="server" /><act:CascadingDropDown ID="ProvinceCDD" runat="server" TargetControlID="ProvinceDDL" Category="Province" PromptText="- Please select a Province -" LoadingText="[Loading Province...]" ServicePath="LocactionService....

How to set a dropdown value in a form based on a value read from a database?
We wish to populate a form based on information read from our database.One of the controls is a dropdown list. We first fill up the ddl from a table of about 60 values. Then we read a value from a different table that was saved data earlier to see which of the 60 values was picked. We wish to show the user that value in the dropdownlist when we display the form. How can we do this?For example, we fill the dropdown list with school course codes (French, German, Math, etc.) , then wish to read a different table in the database and select the dropdown item based on what we r...

radiobuttonlist in a formview control
I'm trying to set the value of a radiobuttonlist control from a value retrieved from the database, which is contained in the "EditItem" template of a formview control. I get the following error message:'RadioButtonList2' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value The value retrieved from the DB for the column "CompletionAction" should be "SR" which should match one of the values of the ListItem control within the radiobuttonlist control.  Any suggestions?  Thanks. Here is the code:<asp:RadioButtonList...

Set checkbox value based on data grid string value
Using Visual Studio 2003, C#, .NET 1.1. I have a web form with a few textboxes, a couple of dropdown lists, and a data grid. The data grid is populated from a SQL stored procedure. The user can select a row to edit by clicking an EDIT link, which triggers an Edit command. The textboxes and dropdowns are then populated with the data from the data grid. I've added a new column to the data grid and a checkbox control. The column is populated with either "YES" or "NO" based on whether the SQL field value is 1 or 0 (integ...

Passing value from one control to another and inserting that value in a table
Hey all, sorry if the subject is confusing or has already been covered, but I have (obviously) a problem (at least one).This is using:Visual Studio 2005ASP.NET 2.0SQL Server 2005 ExpressVisual Basic I'm building a CRM system for my company and have run into a snag when attempting to add new customer records for a given client. The first thing that any CSR (or admin) must do upon accessing the CRM system is choose which client's customers they are actually working with (we have multiple clients and are ultimately responsible for providing customer service to the clients' end ...

Filtering Data For A Table With Given Values (Not Table Values From a Referenced Table)
I need to filter the records displayed for a table with a value provided in a textbox.  I am using a Dynamic Data Entities Website with Visual Basic Programming. Does anyone have a simple example to follow? Thanks for any advice. The only thing I know of without using the 4.0 Preview stuff is Josh Heyes project on codeplex Dynamic Data Filtering you can have a look at my tutorial on how to use it (c# I'm sorry) Dynamic Data Filtering – InstallationSteve Seeking the elegant solution.[Oh! If olny I colud tpye!]c# Bits blogOh, and don't forget to mark as ans...

Select values from one table based upon values in another...
How do I:Select f1, f2, f3, from tb1 where f1=Select f1 from tb2 where f1='condition'?Rex WinnCode-frog System Architects, Inc.VS 2005 Professional, C#, C++ Well... You might try reading up on some standard sql syntax... There are a number of different ways... Select t.f1,t.f2,t.f3 From tb1 t INNER JOIN tb2 t2 ON t.f1 = t2.f1 Where t2.f1 = 'condition'   Select t.f1,t.f2,t.f3 From tb1 t Where t.f1 IN (    Select t2.f1    From tb2 t2    where t2.f1 = 'condition')   Select t.f1,t.f2,t.f3 From tb1 t Where exists (select t2....

If Not value or value then....
Hi all,I want to write a simple IF Not then statement in ASP.net 2.0 and I would like some help please.  If Not ntuser = "DOMAIN\ntuser" Or ntuser = "DOMAIN\ntuser2" Then Panel1.Visible = False End If Doesnt work, can you tell me where i'm going wrong please?many thanks.  The first place you're going wrong is in telling us it "doesn't work" without providing any details. JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. Use Not as stated below. It ...

help with MaskedEditExtender control changing my pre-set value into another value.
I am working on a maintenance application and I am making a use of the Ajax Control Toolkit to apply Client Side validation. This is my first time actually implementing this toolkit into my apps so would like to clear out a couple of issues. My question is that I am populating dollar amounts into a textboxes from a DB query. One of my controls is set up like this: <asp:TextBox ID="txtDollars" runat="server" Width="80"></asp:TextBox> <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender2" ...

Setting control values in Initialize event will not post the new value.
I am having an issue where I need to set the value of a control on my screen in the InitializeRequest event.  Problem is, when I set it at this point, the value does not post, instead the posted value is the value is was before the Asynchronous Post Back is triggered. Below is a very basic example of the problem.  When the page loads I set the value of the  TextBox1 control = "Auto Script".  Now TextBox1 is set to post back when I click the button on the screen.  In my initialize, I try to set the value of the TextBox1 c...

Web resources about - Setting the value of a RadioButtonList based on a value in my sql table. - asp.net.presentation-controls

A2ZMenu tutorial index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Test Your Skill Q. Out of Boxing and ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 1 Jun 2012

DaniWeb Solved Articles - Technology Publication Meets Social Media
An online discussion community of IT professionals. Forums to get free computer help and support. We are a social technology publication covering ...

.NET sample code - developer Fusion
Discover the very latest .NET sample code Out of the box, the ASP.NET list controls (CheckBoxList, RadioButtonList, DropDownList) only support ...

ConditionalRequiredTextValidator Control
The ConditionalRequiredTextValidator control allows you to specify a CheckBox, RadioButton, CheckBoxList, RadioButtonList, DropDownList, or ListBox ...

ASP.NET 4 and Visual Studio 2010 Web Development Overview : The Official Microsoft ASP.NET Site
This document provides an overview of many of the new features for ASP.NET that are included in the.NET Framework 4 and in Visual Studio 2010. ...

Gaiaware - Gaia Ajax
Home Samples Download Free Trial Buy from $195 Login Download Free Trial ASP.NET Done Right 6 reasons to use Gaia Ajax? 40 UI controls 10 aspects/behaviors ...

A2ZMenu utilities index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Online Tool Title Description Rating ...

Online Exam papers index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Test Your Skill Q. Out of Boxing and ...

A2ZMenu Experts Comment
A2ZMenu team is committed in providing solution in various technologies through blogs, tutorials, Q & A etc. Our objective is to give a knowledge ...

Resources last updated: 3/6/2016 10:34:24 PM