Jump to content

DataGrid - Enable/Disable RadioButtonList


Recommended Posts

Subject: DataGrid - Enable/Disable RadioButtonListI am trying to add a RadioButtonList to my datagrid. I am using C#, and VS2005 (C# 3.0, ASP.NET 2.0)I am new to DataGrids. If you can also point me to some websites that haveinfo on the DataGrids, I would be most grateful. (I have some of thebasics down, I would like to see some more advanced features/work-arounds,etc..)I have several issues that I need to address:1) Is there a way to have the list disabled when the page loads, and thenenable it when the Edit button is clicked? I would also like to disablethe list after the Update/Cancel event fires.In the ASPX page, I set the Enabled property of the list to false. I havethe following code in my C# code behind:

protected void dtlGrid_EditCommand      (object source, DataGridCommandEventArgs e)    {        this.dtlGrid.EditItemIndex = e.Item.ItemIndex;        RadioButtonList rblApproveDeny =             (RadioButtonList)              this.dtlGrid.Items[e.Item.ItemIndex].              FindControl("rblApproveDeny");        rblApproveDeny.Enabled = true;        dtlGrid.DataBind();    }void dtlGrid_CancelCommand      (object source, DataGridCommandEventArgs e)    {        this.dtlGrid.EditItemIndex = e.Item.ItemIndex;        RadioButtonList rblApproveDeny =             (RadioButtonList)              this.dtlGrid.Items[e.Item.ItemIndex].              FindControl("rblApproveDeny");        this.dtlGrid.EditItemIndex = -1;        dtlGrid.DataBind();    }

I believe that the Control's Enable feature is what is controlling thevalue of the control. Should I write a JavaScript to change the value, oris there some other place in Code that I can change it?2) (Also related to my RadioButtonList) This is how I have the control in my ASCX file set up:

 <asp:TemplateColumn HeaderText="Approve/Deny">    <itemtemplate>        <asp:RadioButtonList              ID="rblApproveDeny"              runat="server" RepeatDirection="Horizontal"            SelectedIndex=              '<%#              (int.Parse(DataBinder.Eval              (Container.DataItem, "Detail_Status_Code").ToString()) - 1)              %>'            RepeatLayout="Flow" CssClass="tblData" Enabled="true">            <asp:ListItem Value="1" Text="Pending"></asp:ListItem>            <asp:ListItem Value="2" Text="Approve"></asp:ListItem>            <asp:ListItem Value="3" Text="Deny"></asp:ListItem>        </asp:RadioButtonList>    </itemtemplate>    <headerstyle horizontalalign="Center" />    <itemstyle horizontalalign="Center"              Font-Bold="False"              Font-Italic="False"              Font-Overline="False"              Font-Strikeout="False"              Font-Underline="False"              Wrap="False" /></asp:TemplateColumn>

If you notice, I am binding the RadioButtonList with the SelectedIndexproperty. The actual values that the Detail_Status_Code field has are 1,2, and 3. I am unable to directly select my ListItem based on the values.I have to change the field to an "index" value to select the ListItem.Is there a way to have the RadioButtonList search the ListItemsand "select" them where the database field = ListItem.Value?3) (Also related to my RadioButtonList. Sorry.) The value that my RadioButtonList points to is a Status Code. Thestatus' map out to 1 = "Pending", 2 = "Approve", and 3 = "Deny" After looking at problems 1 & 2, is there a way to have the "view" ofthe datagrid display the actual word Pending/Approve/Deny instead of myRadioButtonList, and upon Edit, allow the user to select one of thosevalues? (Would a drop-down list be better here instead of theRadioButtonList?)4) (Not related to the RadioButtonList. YAY!!) Is there a way to exclude some fields from being edited? I don'treally want all of them changed. Just a few.5) (Last one, I promise!) Along the lines of questions 3 & 4, is there a way to display one kindof control while the grid is in "View" mode, and then show a totalydifferent control in "Edit" mode?Thank you for all of your help. -Bryan Clauss

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...