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

Discussion in 'ASP .Net' started by Empire City, Apr 29, 2004.

  1. Empire City

    Empire City Guest

    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.aspx?scid=kb;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;

    }

    }

    }

    }
    Empire City, Apr 29, 2004
    #1
    1. Advertising

  2. RE: CheckBoxList In A DataGrid - Can I get what's selected without usi

    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
    =?Utf-8?B?bWFoc2E=?=, Jun 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schultz
    Replies:
    3
    Views:
    555
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  2. CodeCowboy

    CheckBoxList in DataGrid Edit-Mode

    CodeCowboy, Mar 2, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    761
    CodeCowboy
    Mar 2, 2005
  3. Patrick.O.Ige
    Replies:
    5
    Views:
    19,098
    Patrick.O.Ige
    Jun 19, 2005
  4. Andreas Klemt
    Replies:
    0
    Views:
    292
    Andreas Klemt
    Oct 8, 2003
  5. asp123 vbnet via .NET 247

    Adding Checkboxlist/checkbox to dataGrid and retrieving selected value

    asp123 vbnet via .NET 247, Mar 25, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    620
    asp123 vbnet via .NET 247
    Mar 25, 2005
Loading...

Share This Page