[RESOLVED] RadioButtonList with extra controls

Hello all,

One thing that I have come acrossed several times is radio button list but I always skipped that. Now I want to continue that.

I want to show some extra controls with radio buttons, that is I would like to use RadioButtonList with other controls.

This list shows only text bydefault. How we can show for example an image with each radiobutton. the pattern is below..

RadioButton1   Image1

RadioButton2   Image2

RadioButton3   Image3

I do not want to use html control and also want to collect the selected button in code behind.

Another pattern is 

RadioButton1 

  Checkbox1

RadioButton1  

  Textbox

RadioButton1  

  Image1

Kindly tell me how to create these patters with server radiobuttonlist control and how get that what button is selected in

code behind.

Thanks...






My suggestion would be to create some custom server controls that inherit from the RadioButton or RadioButtonList.  All you'd need to do is add the similar HTML to the control from a public property you expose to the user to input data into. 

Another way would be to do something like this for the first scenario:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
    SelectCommand="SELECT Name, StateProvinceID, Name + ' &lt;img src=''App_Themes/MyTheme/Images/searchicon.png'' /&gt;' AS NameImage FROM [Person].[StateProvince] ORDER BY [Name]">
</asp:SqlDataSource>
<asp:RadioButtonList ID="rbl1" runat="server" DataSourceID="SqlDataSource1" DataTextField="NameImage" DataValueField="StateProvinceID" RepeatColumns="3" RepeatLayout="Table" RepeatDirection="Vertical" />

Of course you don't need to use searchicon.png with every record you could use another database field to get the image source. 

As I mentioned, the more robust solution would be to create our own custom control (either server or user)

 

b471code3

As I mentioned, the more robust solution would be to create our own custom control (either server or user)

Can you please give some exaple of it, or any link covering the topic I am asking...

Thanks

What language do you write in, VB or C#. I will look through some of my code and share with you.

Broadly I work on C#, but vb.net is also fine... Currently working with C# so I would go for C#

Thanks...

Here is a pretty simple example of a UserControl you can implement for a checkbox with an image.  Simalar controls can be built using this example but remember if you want to set properties of controls within the ascx control you have to publicly expose them.

Creating the ascx control:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RadioButtonImage.ascx.cs" Inherits="controls_RadioButtonImage" %>
<asp:CheckBox ID="CheckBox1" runat="server" oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="true" />&nbsp;
<asp:Image ID="Image1" runat="server" />

ascx control code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public delegate void CheckChangedEventHandler(object sender, EventArgs e);

public partial class controls_RadioButtonImage : System.Web.UI.UserControl
{
    /// <summary>
    /// Property to set the imageurl of the image.
    /// </summary>
    public string ImageUrl 
    {
        get { return Image1.ImageUrl; }
        set { Image1.ImageUrl = value; }
    }

    /// <summary>
    /// Property to set the Checkboxes text property.
    /// </summary>
    public string CheckBoxText
    {
        get { return CheckBox1.Text; }
        set { CheckBox1.Text = value; }
    }

    /// <summary>
    /// Property to set the checkboxes checked property.
    /// </summary>
    public bool CheckBoxChecked
    {
        get { return CheckBox1.Checked; }
        set { CheckBox1.Checked = value; }
    }

    public bool AutoPostBack
    {
        get { return CheckBox1.AutoPostBack; }
        set { CheckBox1.AutoPostBack = value; }
    }

    public event CheckChangedEventHandler CheckChanged;
    protected virtual void OnCheckChanged(EventArgs e)
    {
        if (CheckChanged != null)
        {
            CheckChanged(this, e);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    /// <summary>
    /// Capture the check changed event for the publicly exposed event.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        OnCheckChanged(EventArgs.Empty);
    }
}

Using the ascx control on a page:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<%@ Register src="controls/RadioButtonImage.ascx" tagname="RadioButtonImage" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:RadioButtonImage ID="RadioButtonImage1" runat="server" ImageUrl="~/App_Themes/KwikTrip/images/home.gif" OnCheckChanged="RadioButtonImage1_CheckChanged" CheckBoxText="I'm a checked box" CheckBoxChecked="true" />
    </div>
    </form>
</body>
</html>

Capturing the click event for the user control on the page:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void RadioButtonImage1_CheckChanged(object sender, EventArgs e)
    {
        if (RadioButtonImage1.CheckBoxChecked)
        {
            RadioButtonImage1.CheckBoxText = "I'm a checked box";
        }
        else
        {
            RadioButtonImage1.CheckBoxText = "How dissapointing, I'm not checked";
        }
    }
}

 

[RESOLVED] How to track stock prices dynamically

Hi!! I am developing a website for which i need to track values of stocks of some companies dynamically from some website.

Does anyone can help me with this???

Thanks

Contact that site and ask if they provide a (web) service that could be used in your application, or if you may grab their data. Read this post for more details.

[RESOLVED] Show div

Hello,

I am having div in my page which is invisible. I want to show it on button click using Javascitp.

How to do this ?

<input id="Button1"  type="button" value="Update" onclick="ShowStatus();" />
                    <div style="display:none" id="DivStatus"></div>

like this - 

    <script type="text/javascript">
        function toggle(divid) {
            divelement = document.getElementById(divid);
            divelement.style.display = (divelement.style.display == 'block') ? 'none' : 'block';
        }
</script><a href="#" onclick="toggle('div1');">Show/Hide</a>
<div id="div1" style="displayblock;">Hello, World</div>

[RESOLVED] master page does not load

hi..

Iam new asp.net and use visaul web developer 2010 , I have used master page to make my webpages uniform but the masterpage doesnot load

here is my code

 My index page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="file_upload.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <style type="text/css">
         .back
         {
            background-color:Silver;
         }
    </style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
       <asp:ContentPlaceHolder ID="header" runat="server">

       </asp:ContentPlaceHolder>
</head>
<body runat="server">
    <form id="form1" runat="server">
  
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            daaa
            <center>
                <img src="../f_lms_flash_banner_video.jpg" />
                <br />
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Index.aspx">Main</asp:HyperLink>
                &nbsp;<asp:HyperLink ID="HyperLink2" runat="server">Upload</asp:HyperLink>
                &nbsp;<asp:HyperLink ID="HyperLink3" runat="server">Log out</asp:HyperLink>
                &nbsp;<asp:HyperLink ID="HyperLink4" runat="server">Log in</asp:HyperLink>
            </center>

        </asp:ContentPlaceHolder>
   
    </form>
</body>
</html>
 
My masterpage:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="file_upload.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <style type="text/css">
         .back
         {
            background-color:Silver;
         }
    </style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
       <asp:ContentPlaceHolder ID="header" runat="server">

       </asp:ContentPlaceHolder>
</head>
<body runat="server">
    <form id="form1" runat="server">
  
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            daaa
            <center>
                <img src="../f_lms_flash_banner_video.jpg" />
                <br />
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Index.aspx">Main</asp:HyperLink>
                &nbsp;<asp:HyperLink ID="HyperLink2" runat="server">Upload</asp:HyperLink>
                &nbsp;<asp:HyperLink ID="HyperLink3" runat="server">Log out</asp:HyperLink>
                &nbsp;<asp:HyperLink ID="HyperLink4" runat="server">Log in</asp:HyperLink>
            </center>

        </asp:ContentPlaceHolder>
   
    </form>
</body>
</html>

 

In the masterpage file, try moving the content you have inside the contentplaceholder, to outside the contentplaceholder. The contentplaceholder is where the content pages render their contents.

Hello Danar

Why Are You Writing HTML And Form Tage in ur aspx page?in master page u are keeping content placeholder and in that contentplaceholder u can put u can put part that is going to change every time.that means ur masterplaceholder alredy have html and form tag and ur content placeholder load rest desing at runtime so no need that tags in ur index page.

http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx

thank u for helping

[RESOLVED] website templates sites

can you till me recommend website templates sites

(free or buy)

if you don't mind shelliung out  few $$$ then try Artisteer.  You can create asp.net templates.

http://www.artisteer.com/

 

Hi,

if a template helps you than use one. If you search on the web you will find sites like