suresh pondicherry
asked on
get radiobutton list from C# xml
Hi Experts,
In my aspx page , i need to display radio button lists from the xml input.
My xml is
<gas><level>Required</leve l><list><l istitem i='0'>adress1, street1, state, zip </listitem><listitem i='1'>adress1, street1, state1, zip1 </listitem><listitem i='2'>adress2, street2, state2, zip2 </listitem><listitem i='3'>adress3, street3, state3, zip3 </listitem><listitem i='4'>adress4, street4, state4, zip4 </listitem></list></gas>
i need to get
radio button1 adress1, street1, state1, zip1
radio button2 adress2, street2, state2, zip2
radio button3 adress3, street3, state3, zip3
radio button4 adress4, street4, state3, zip4
if Radiobutton1 is selected , should display respective fields in
4 text boxes,
similarly for other radio buttons clicks.
Kind Regards,
Pooja
In my aspx page , i need to display radio button lists from the xml input.
My xml is
<gas><level>Required</leve
i need to get
radio button1 adress1, street1, state1, zip1
radio button2 adress2, street2, state2, zip2
radio button3 adress3, street3, state3, zip3
radio button4 adress4, street4, state3, zip4
if Radiobutton1 is selected , should display respective fields in
4 text boxes,
similarly for other radio buttons clicks.
Kind Regards,
Pooja
Hello Pooja,
Please check the link:
http://niitdeveloper.blogspot.com/2010/08/generating-dynamic-controls-based-on.html
I tried for the code and hope I am able to do as you needed. I am trying to upload the code but network speed going slow. So it would take time but the code there is easy to understand.
Let us know back if your problem solved or not.
Regards,
VSS
Please check the link:
http://niitdeveloper.blogspot.com/2010/08/generating-dynamic-controls-based-on.html
I tried for the code and hope I am able to do as you needed. I am trying to upload the code but network speed going slow. So it would take time but the code there is easy to understand.
Let us know back if your problem solved or not.
Regards,
VSS
ASKER
Hi Vs00saini,
Please find my code, I could get the event generated.
private void CreateRadioButtons(ArrayLi st elements)
{
for (int i = 0; i < elements.Count; i++)
{
RadioButton rbutton = new RadioButton();
string itemName = string.Empty;
string txtItem = string.Empty;
txtItem = elements[i].ToString();
itemName = itemName + (rbList.Items.Count + 1);
ListItem newListItem = new ListItem(string.Format("<b >{0}</b>", txtItem), itemName, true);
rbList.Items.Add(newListIt em);
rbutton.CheckedChanged += new System.EventHandler(RadioB utton_Chec kedChanged );
}
}
private void RadioButton_CheckedChanged (object sender, EventArgs e)
{
RadioButton checkRadio = (RadioButton)sender;
String[] arrValues=new String[4];
arrValues = checkRadio.Text.Split(',') ;
if (arrValues.Length > 0)
{
//txtAddress.Text = arrValues[0].ToString();
//txtStreet.Text = arrValues[1].ToString();
//txtState.Text = arrValues[2].ToString();
//txtZip.Text = arrValues[3].ToString();
}
}
Kind Regards,
Pooja
Please find my code, I could get the event generated.
private void CreateRadioButtons(ArrayLi
{
for (int i = 0; i < elements.Count; i++)
{
RadioButton rbutton = new RadioButton();
string itemName = string.Empty;
string txtItem = string.Empty;
txtItem = elements[i].ToString();
itemName = itemName + (rbList.Items.Count + 1);
ListItem newListItem = new ListItem(string.Format("<b
rbList.Items.Add(newListIt
rbutton.CheckedChanged += new System.EventHandler(RadioB
}
}
private void RadioButton_CheckedChanged
{
RadioButton checkRadio = (RadioButton)sender;
String[] arrValues=new String[4];
arrValues = checkRadio.Text.Split(',')
if (arrValues.Length > 0)
{
//txtAddress.Text = arrValues[0].ToString();
//txtStreet.Text = arrValues[1].ToString();
//txtState.Text = arrValues[2].ToString();
//txtZip.Text = arrValues[3].ToString();
}
}
Kind Regards,
Pooja
Hi Pooja,
Do you need some clarification for code you written or if you are showing it as the objective you achieved.
Regards,
VSS
Do you need some clarification for code you written or if you are showing it as the objective you achieved.
Regards,
VSS
ASKER
Hi VS00saini,
I need some help and clarification. I some what dropped an idea of using xml since it ruled out my time . so i could get the source in dictionary and i could poup up the radio button list. i need to get the respective radio text selected when any any of the radio get clicked. i can send my code if u want.
Kind Regards,
Pooja
I need some help and clarification. I some what dropped an idea of using xml since it ruled out my time . so i could get the source in dictionary and i could poup up the radio button list. i need to get the respective radio text selected when any any of the radio get clicked. i can send my code if u want.
Kind Regards,
Pooja
Hi,
Some doubts regarding your query:
(1) Popup the radiobutton list ... Do you want popup window to show radiobuttonlist.
(2) Get the source in dictionary ..... You mean to say the source of radiobuttonlist would come from Systen.Collections.Generic .Dictionar y.
Regards,
V.S.Saini
Some doubts regarding your query:
(1) Popup the radiobutton list ... Do you want popup window to show radiobuttonlist.
(2) Get the source in dictionary ..... You mean to say the source of radiobuttonlist would come from Systen.Collections.Generic
Regards,
V.S.Saini
Hi Pooja,
I think I have done the coding as you mentioned in your statement. Modify it according to your requirements.
Regards,
V.S.Saini
I think I have done the coding as you mentioned in your statement. Modify it according to your requirements.
Regards,
V.S.Saini
-----------------------------
//Default.aspx
-----------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Dictionary Collection</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Passing values from here to there</h2><hr />
<asp:Button ID="btnGet" runat="Server" Text="Go to Second" OnClick="btnGet_Click" />
</div>
</form>
</body>
</html>
--------------------------
//Default.aspx.cs
--------------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized; //Namespace added
public partial class _Default : System.Web.UI.Page
{
HybridDictionary hd;
protected void Page_Load(object sender, EventArgs e)
{
hd = new HybridDictionary(4, true);
hd.Add("first", "address1, street1,state,zip");
hd.Add("second", "address2, street2,state,zip");
hd.Add("third", "address3, street3,state,zip");
hd.Add("fourth", "address4, street4,state,zip");
}
public HybridDictionary myValues
{
get
{
return hd;
}
}
protected void btnGet_Click(object sender, EventArgs e)
{
Server.Transfer("~/Second.aspx?Dic=" + hd, true);
}
}
------------------------------------
//Second.aspx
-------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Second.aspx.cs" Inherits="Second" %>
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
<!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>Create RadioButtonList</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Generating radiobuttonlist dynamically</h2><hr />
<asp:Panel ID="panelRadio" runat="Server" BackColor="Orange"></asp:Panel>
<br />
Address: <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox><br />
Street: <asp:TextBox ID="txtStreet" runat="server"></asp:TextBox><br />
State: <asp:TextBox ID="txtState" runat="server"></asp:TextBox><br />
Zip:<asp:TextBox ID="txtZip" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
----------------------------
Second.aspx.cs
----------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.Collections.Generic;
public partial class Second : System.Web.UI.Page
{
static int counter;
static HybridDictionary hd2;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
hd2 = PreviousPage.myValues;
}
ArrayList elements = new ArrayList();
// Loop through list
foreach (object k in hd2.Values)
{
elements.Add(k);
}
if (elements.Count > 0)
{
CreateRadioButtons(elements);
counter++;
}
}
private void CreateRadioButtons(ArrayList elements)
{
RadioButtonList rbl = new RadioButtonList();
rbl.EnableViewState = true;
rbl.AutoPostBack = true;
rbl.SelectedIndexChanged += new EventHandler(rbl_SelectedIndexChanged);
this.panelRadio.Controls.Add(rbl);
if (rbl.Items.Count > 0)
{
rbl.Items.Clear();
}
for (int i = 0; i < elements.Count; i++)
{
// Create Radio Button
ListItem item = new ListItem();
item.Text = elements[i].ToString();
item.Value = elements[i].ToString();
// Adding to container
if (panelRadio.Controls.Count>0)
{
rbl.Items.Add(item);
}
}
}
protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rbl2 = (RadioButtonList)sender;
String[] arrValues = new String[4];
arrValues = rbl2.Text.Split(',');
if (arrValues.Length > 0)
{
txtAddress.Text = arrValues[0].ToString();
txtStreet.Text = arrValues[1].ToString();
txtState.Text = arrValues[2].ToString();
txtZip.Text = arrValues[3].ToString();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Arun
Open in new window