This is a migrated thread and some comments may be shown as answers.

InsertItem command not opening the EditForm

1 Answer 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 2
Andy asked on 30 Mar 2011, 10:36 PM
When I click "Add a new record", the Loading... icon at the bottom of the grid spins continuously, but the Edit works fine.

Actually, I found the problem, but I'm not sure how to fix it.

The EditFormType is Template. In the template I have the following:
<td>
    <asp:RadioButtonList ID="CommentLevel_RadioButtonList" runat="server"
                 DataSourceID="CommentLevel_SqlDataSource" DataTextField="CodeValue"
                 DataValueField="CodeName" RepeatDirection="Horizontal"
        
SelectedValue='<%# Eval("CommentCategory") %>'>
    </asp:RadioButtonList>
</td>

The problem is with the SelectedValue. When editing an existing record, there is a value in CommentCategory; but when inserting it is null.

What is the best way for me to conditionally include the SelectedValue property? On a new record, I want don't want a default value -- the user needs to think about which it should be. (An error message displays before saving if null.)

1 Answer, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 31 Mar 2011, 06:09 AM
hi Andy

protected void rdgrid_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
        
       {
           GridEditFormItem edititem = (GridEditFormItem)e.Item;
 
    Label lblComment = edititem.FindControl("lblComment") as Label;
                RadioButtonList CommentLevel_RadioButtonList= edititem.FindControl("CommentLevel_RadioButtonList") as RadioButtonList;
    if(!string.IsNullOrWhiteSpace(lblComment.Text))
    {
        CommentLevel_RadioButtonList.SelectedValue = lblComment.Text;
                }
       }
   }

<td>
<asp:Label ID="lblComment" runat="Server"  Text='<%# Eval("CommentCategory") %>' Visible="false"></asp:Label>
    <asp:RadioButtonList ID="CommentLevel_RadioButtonList" runat="server"
                 DataSourceID="CommentLevel_SqlDataSource" DataTextField="CodeValue"
                 DataValueField="CodeName" RepeatDirection="Horizontal">
    </asp:RadioButtonList>
</td>


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Andy
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or