I am trying to add a RadioButtonList to my datagrid. I am using C#, and VS
2005 (C# 3.0, ASP.NET 2.0)
I am new to DataGrids. If you can also point me to some websites that have
info on the DataGrids, I would be most grateful. (I have some of the
basics 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 then
enable it when the Edit button is clicked? I would also like to disable
the list after the Update/Cancel event fires.
In the ASPX page, I set the Enabled property of the list to false. I have
the 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 the
value of the control. Should I write a JavaScript to change the value, or
is 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 SelectedIndex
property. 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 ListItems
and "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. The
status' map out to 1 = "Pending", 2 = "Approve", and 3 = "Deny"
After looking at problems 1 & 2, is there a way to have the "view" of
the datagrid display the actual word Pending/Approve/Deny instead of my
RadioButtonList, and upon Edit, allow the user to select one of those
values? (Would a drop-down list be better here instead of the
RadioButtonList?)
4) (Not related to the RadioButtonList. YAY!!)
Is there a way to exclude some fields from being edited? I don't
really 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 kind
of control while the grid is in "View" mode, and then show a totaly
different control in "Edit" mode?
Thank you for all of your help.
-Bryan Clauss
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com