Search code examples
data-bindingbindinginsertrad

RadControls ListView Insert Template Help?


I have just started using RadControls so this question might be basic for you, I am using a List View which I am populating using Sql Data Source, I also have insert functionality in that List View but the problem is the insert template just disappear after adding one record and I have to refresh the page to make insert template appear again, am I doing something wrong ?

I have another question regarding Rad List View, is it possible that we use a drop down box instead of a text box inside insert template ? because sometimes you want to restrict the users to pick from predefined values instead of letting them enter anything ? I have tried putting drop down box inside insert template using code view of visual studio and it also appears properly when I run the page but the problem is data binding is not working, I have tried using

SelectedValue=<%# Bind("field_name") %>

as it was used in case of textbox like

Text=<%# Bind("field_name") %)>

but it does not work for some reason.

Please advice, Thanks.


Solution

  • Ok I got it, maybe it will help someone.

                            <tr>
                            <td>
                                <asp:Label ID="DEPARTMENTLabel2" runat="server" 
                                    AssociatedControlID="DEPARTMENTTextBox" Text="DEPARTMENT"></asp:Label>
                            </td>
                            <td>
                                 <asp:DropDownList ID="DEPARTMENTTextBox" runat="server" SelectedValue='<%# Bind("DEPARTMENT") %>'>
                                 <asp:ListItem Text="Admin" Value="Admin">Admin</asp:ListItem>
                                 <asp:ListItem Text="Editing" Value="Editing">Editing</asp:ListItem>
                                 <asp:ListItem Text="Sales and Support" Value="Sales and Support">Sales and Support</asp:ListItem>
                                 <asp:ListItem Text="Writing" Value="Writing">Writing</asp:ListItem>
                                 </asp:DropDownList>
                            </td>
                        </tr>
    

    Change the default textbox to a dropdown and assign its ID to AssociatedControlID of label that is representing it, here I used the same ID which was originally assigned to it "DEPARTMENTTextBox" (just to be careful), you can change it to "DEPARTMENTDropDown" or any ID you like but make sure you make these changes everywhere in the RADListView so that it performs normally.

    As for the insert template disappearing after adding one record, I made a workaround and placed a button for "add another record" such that when it is clicked it calls this code.

    protected void btnAddAnother_Click(object sender, EventArgs e)
    {
        RLVUsers.ShowInsertItem(RadListViewInsertItemPosition.LastItem);
    }
    

    This button make insert template reappear and allow the user to add another record.