0

I'm using visual studio C#
I have gridView and I checked enable selection
I have radioButtonList with two values
when the page load I want the cloumn with the selection to be hidden, but when the user choose one of the radioButton the selection column will be visbale

Here is what I did, but I don't know why it's not working

    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.Columns[8].Visible = false; 
    }

    protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        GridView1.Columns[8].Visible = true;
    }

I also tried this, but also it's not working

    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.Columns[8].Visible = false; 
        if (RadioButtonList1.Items[0].Selected == true || RadioButtonList1.Items[1].Selected == true)
        {
            GridView1.Columns[8].Visible = true;
        }
    }

Edited by pritaeas: Removed spacing.

3
Contributors
8
Replies
42
Views
3 Years
Discussion Span
Last Post by ddanbe
0

please can some one help me
If my question is not clear I will try to explain it more

0

A radiobutton is used in a group to turn one selection on and all the rest off. You better use one checkbox, to turn something on or off.

0

perhaps something like this will work:

        protected void Page_Load(object sender, EventArgs e)
        {
            ShowColumns();
        }
        protected void ShowColumns()
        {
            GridView1.Columns[0].Visible = RadioButtonList1.Items[0].Selected;
            GridView1.Columns[1].Visible = RadioButtonList1.Items[1].Selected;
        }
        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowColumns();
        }
0

Yes tinstaafl, you are probabaly right, but as I said, don't use a radiobutton in this case.
Rewrite your code, using a checkbox control. I can do it using just 3 lines!

0

sorry I guess I missed the memo that named you God's replacement. If OP wants and likes radio buttons, and the code to use them is easy(only 2 lines) and within the bounds of what the language will allow, who is anybody to say what is irrevocably wrong or right. Especially with, only personal preference as the reason and no real underlying reason(i.e. unstable code, high memory usage, etc.), or a concrete example to use as an alternative.

Edited by tinstaafl

0

Ha, ha :) that is not what I meant. The OP can do whatever he likes, I just give him advice to improve. And yes, I already have used a screwdriver like a hammer, but ask any craftsman(woman), he(she) will advise me not to do so!
You could easily use a textboxcontrol like an OK button, if you like that, fine with me. But I would advise you not to do so.

0

Yuo must excuse me,(and please correct me!) if I don't always grasp the subtleties of the English language, because I'm not a native speaker of it.

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.