473,480 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CheckBoxList In A DataGrid - Can I get what's selected without using the Edit

I have an ASP.NET form with a DataGrid and Button. I want to put a
RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a
ListItem in the cell. The display part works fine. I then check some boxes
and hit the submit button. I can't seem to get the value that is selected on
the RadioButton List. I don't want to use the EditTemplate thing I just want
to click on the radiobutton and submit the form. I also don't want to do
autopostbacks when I click on a button. Can this be done?

I looked at this link:
http://support.microsoft.com/default...b;en-us;320707

I modified the code to work with a RadioButton List not just a RadioButton.
However from each RadioButton List when I cycle throug the GridItems it
tells me that one of the buttons in the list was selected but I can't seem
to get which one.

Here is my test:

using System;

using System.Text;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace DataGridRadio

{

public class GridList

{

//Constructors

public GridList() {}

public GridList(

string description,

ArrayList bValue)

{

this.Description = description;

this.BValue = bValue;

}

//Properties

private string description;

private ArrayList bValue;

public string Description

{

get {return description;}

set {description = value;}

}

public ArrayList BValue

{

get {return bValue;}

set {bValue = value;}

}

}

public class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.DataGrid DataGrid1;

protected System.Web.UI.WebControls.Label Message;

protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)

{

ArrayList blist1 = new ArrayList();

ListItem li1 = new ListItem("aaa", "111");

blist1.Add(li1);

ListItem li2 = new ListItem("bbb", "222");

blist1.Add(li2);

ListItem li3 = new ListItem("ccc", "333");

blist1.Add(li3);
ArrayList blist2 = new ArrayList();

ListItem li4 = new ListItem("ddd");

blist2.Add(li4);

ListItem li5 = new ListItem("eee");

blist2.Add(li5);

ListItem li6 = new ListItem("fff");

blist2.Add(li6);

ArrayList blist3 = new ArrayList();

ListItem li7 = new ListItem("ggg");

blist3.Add(li7);

ListItem li8 = new ListItem("hhh");

blist3.Add(li8);

ListItem li9 = new ListItem("iii");

blist3.Add(li9);

ArrayList alist1 = new ArrayList();

GridList gl1 = new GridList("aaaaaaaaaaa", blist1);

alist1.Add(gl1);

GridList gl2 = new GridList("bbbbbbbbbbb", blist2);

alist1.Add(gl2);

GridList gl3 = new GridList("ccccccccccc", blist3);

alist1.Add(gl3);

DataGrid1.DataSource = alist1;

DataGrid1.DataBind();

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Button1.Click += new System.EventHandler(this.Button1_Click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void Button1_Click(object sender, System.EventArgs e)

{

StringBuilder gridSelections = new StringBuilder();

//Loop through each DataGridItem, and determine which CheckBox controls

//have been selected.

foreach(DataGridItem DemoGridItem in DataGrid1.Items)

{

RadioButtonList myRadioButtonList =

(RadioButtonList)DemoGridItem.Cells[1].Controls[1];

bool b4 = myRadioButtonList.Items[1].Selected;

int b1;

b1 = myRadioButtonList.SelectedIndex;

ListItem b2 = new ListItem();

b2 = myRadioButtonList.SelectedItem;

int b3 = 2;

}

}

}

}




Nov 18 '05 #1
1 2374
Hi I have a data list that have radio button when I click on edit button I loose all the radiobuttons that click they are seems not choosen,I set auto post back in both data list and rdio button

Nov 18 '05 #2

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

Similar topics

0
3033
by: Francois Verbeeck | last post by:
Dear UseNet readers, Does anyone have any idea on how to colorize selected checkbox in checkboxlist control ? I've quite a huge checkboxlist (approximatively one full screen) and, to improve...
1
5372
by: Tom | last post by:
Hi, I have a webform which has DropDownList, RadioButtonList and CheckBoxList. All values are in webform, but not select from DB table as they do not need to be used as search requirements. ...
4
8056
by: dm_dal | last post by:
Is there a know issue surrounding the CheckBoxList control and it's viewstate? When my control is created, it's ListItems are checked as needed, but on a postback, they loose their Selected...
0
1528
by: D. Shane Fowlkes | last post by:
OK - I'm looking for the best approach on how to do this. I have a form page where the user can edit their "Profile" (data) which is in SQL Server. It's your basic company information - address,...
0
1592
by: D. Shane Fowlkes | last post by:
OK - I'm looking for the best approach on how to do this. I have a form page where the user can edit their "Profile" (data) which is in SQL Server. It's your basic company information - address,...
4
4024
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
0
1173
by: riteshraha | last post by:
I cant retrieve selected item from checkboxlist in asp.net project. when i submit multiple item from checkboxlist it works fine. but when i am trying to edit this items then checkboxlist does not...
6
3480
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
3
2762
by: dbuchanan | last post by:
How, at rundime, do I capture the fact that the parametrized query that fills a CheckBoxList results in an empty set. When the dataset is empty the CheckBoxList does not appear. I would like to...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
6956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5342
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.