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

Dropdown Box Controls - Different In edit and Insert Mode

0 Answers 46 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Julie3
Top achievements
Rank 1
Julie3 asked on 13 Jan 2015, 04:29 PM
I have 2 tables which are related - Clients and ClientContact.

Clients -
ClientID int32
Company varchar
Active bit

ClientContact
ClientID int32
ClientContact varchar

When I use the dropdownlist control on the contact page and set the data source to only show active clients, if the current company is not active it disappears in in edit mode - should I be adding the current value in programmatically or changing the list on insert mode?

 <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
                    AllowSorting="true" AllowAutomaticUpdates="True" AutoGenerateColumns="False" AllowFilteringByColumn="true"
                    DataSourceID="dsContacts" OnDataBound="RadGrid1_DataBound" ShowStatusBar="true" OnItemDataBound="RadGrid1_ItemDataBound" OnInsertCommand="RadGrid1_OnInsertCommand"
                    OnPreRender="RadGrid1_PreRender">
                    <PagerStyle Mode="NextPrevAndNumeric" />
                    <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ClientContactID"
                        DataSourceID="dsContacts" HorizontalAlign="NotSet" Font-Names="Arial"   Font-Size="8" >
                        <CommandItemSettings AddNewRecordText="Add new contact" />
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton">
                                <HeaderStyle Width="20px" />
                                <ItemStyle CssClass="MyImageButton" />
                            </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="ClientContactID" DataType="System.Int32" HeaderText="ContactID"
                        ReadOnly="True" SortExpression="ClientContactID" UniqueName="ClientContactID" Display="False">
                    </telerik:GridBoundColumn>                    
                    <telerik:GridDropDownColumn DataField="ClientID" DataSourceID="dsClient" HeaderText="Client"
                        ListTextField="Company" ListValueField="ClientID" UniqueName="ClientID" Display="False">
                    </telerik:GridDropDownColumn>  
                    
                           
                            <telerik:GridTemplateColumn HeaderText="Name" SortExpression="ClientContact" UniqueName="TemplateColumn1"
                                Display="False" EditFormColumnIndex="0">
                                <EditItemTemplate>
                                    <br />
                                    <asp:TextBox runat="server" ID="tbName" Text='<%# Bind("ClientContact") %>' Width="400px"></asp:TextBox>
                                    <span style="color: Red">*</span>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbName"
                                        ErrorMessage="This field is required" runat="server">
                                    </asp:RequiredFieldValidator>
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="ClientContact" HeaderText="Client Contact" SortExpression="ClientContact"
                                UniqueName="ClientContact" ReadOnly="True">
                            </telerik:GridBoundColumn>
                             
                                           
                                                      
                        </Columns>
                         <EditFormSettings >
                        <EditColumn ButtonType="ImageButton" />
                    
                </EditFormSettings>
                    </MasterTableView>
                    <ValidationSettings CommandsToValidate="PerformInsert,Update" />
                </telerik:RadGrid>

                 <asp:SqlDataSource ID="dsClient" runat="server" ConnectionString="<%$ ConnectionStrings:connDatabase %>"
                    SelectCommand=" SELECT * FROM [Clients]   ORDER BY [Company] ">
                </asp:SqlDataSource>

Code Not Working
        protected void RadGrid1_OnInsertCommand(object sender, EventArgs e)
        {
            SqlConnection conn = null;

            //  Create a connection to the "pubs" database located
            // on the local computer.
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connDatabase"].ConnectionString);

            // Connect to the SQL database using a SQL SELECT query to get
            // all the data from the "Titles" table.
            SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM Clients WHERE Active=1 ORDER BY Company", conn);
            // Create and fill a DataSet.
            DataSet ds = new DataSet();
            myCommand.Fill(ds);


            //GridEditableItem item = e.Item as GridEditableItem;
           // DropDownList list = item.FindControl("ClientID") as DropDownList;
           // list.DataSource = ds;
            //list.DataTextField = "Company";
            //list.DataValueField = "Company";
            //list.DataBind();


        }

No answers yet. Maybe you can help?

Tags
DropDownList
Asked by
Julie3
Top achievements
Rank 1
Share this question
or