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;
        }
    }

Recommended Answers

All 8 Replies

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

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.

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();
        }

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!

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.

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.

Except your wording wasn't advise it was a command

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.