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

[Solved] Getting dropdown value when updating Grid

5 Answers 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amarinder Singh
Top achievements
Rank 1
Amarinder Singh asked on 29 Jan 2010, 06:57 AM

Hello,

I am facing one problem. I have used GridTemplate and have dropdown in edit mode as shown below.

 <telerik:GridTemplateColumn UniqueName="StatusColumn" HeaderText="Approved Status">  
                <ItemTemplate> 
                   <asp:Label id="lblStatus" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "status") %>'>  
                       
                   </asp:Label> 
                </ItemTemplate> 
                <EditItemTemplate> 
                   <asp:DropDownList id="ddlApprovalStatus" runat="server" > 
                    <asp:ListItem Text="Pending" Value="False"></asp:ListItem> 
                   <asp:ListItem Text="Approved" Value="True"></asp:ListItem> 
                   </asp:DropDownList> 
                                  </EditItemTemplate> 
                <ItemStyle Width="40px" /> 
            </telerik:GridTemplateColumn> 

I had set AllowAutomaticUpdates="True" of Rad grid and binding grid with SqlDataSource
i had set status field in database as bit. Now if i update the record in grid then it set null in database. I suppose it doesn't pick the dropdown value and is picking the textvalue, and bit datatype in database in not able to store my text, that is why its storing null.

How to pick selected value field of dropdown?
I am using SqpDataSource like this
<asp:SqlDataSource ID="SqlDataSource1" runat="server"   
    ConnectionString="<%$ ConnectionStrings:test %>"   
    DeleteCommand="DELETE FROM [Test] WHERE [id] = @id"   
    InsertCommand="INSERT INTO [Test] ([name], [phone], [email], [company], [status]) VALUES (@name, @phone, @email, @company,@StatusColumn)"   
    SelectCommand="SELECT [id], [name], [phone], [email], [company], [status], [username], [password], [cmsmemberid] FROM [ltsConsultant]"   
    UpdateCommand="UPDATE [Test] SET [name] = @name, [phone] = @phone, [email] = @email, [company] = @company,  [status] = @StatusColumn WHERE [id] = @id">  
    <DeleteParameters> 
        <asp:Parameter Name="id" Type="Int32" /> 
    </DeleteParameters> 
    <UpdateParameters> 
        <asp:Parameter Name="name" Type="String" /> 
        <asp:Parameter Name="phone" Type="String" /> 
        <asp:Parameter Name="email" Type="String" /> 
        <asp:Parameter Name="company" Type="String" /> 
        <asp:Parameter Name="StatusColumn" Type="String" /> 
        <asp:Parameter Name="id" Type="Int32" /> 
    </UpdateParameters> 
    <InsertParameters> 
        <asp:Parameter Name="name" Type="String" /> 
        <asp:Parameter Name="phone" Type="String" /> 
        <asp:Parameter Name="email" Type="String" /> 
        <asp:Parameter Name="company" Type="String" /> 
        <asp:Parameter Name="StatusColumn" Type="String" /> 
    </InsertParameters> 
</asp:SqlDataSource> 

5 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 29 Jan 2010, 10:02 AM
Hi Amarinder,

Just add the following property binding expression to your dropdown list:

SelectedValue='<%# Bind("status") %>'

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amarinder Singh
Top achievements
Rank 1
answered on 29 Jan 2010, 10:05 AM
Hello,

 i added SelectedValue='<%# Bind("status") %>' at

 

<EditItemTemplate> 
                   <asp:DropDownList id="ddlApprovalStatus" runat="server" SelectedValue='<%# Bind("status") %>' > 
                    <asp:ListItem Text="Pending" Value="False"></asp:ListItem> 
                   <asp:ListItem Text="Approved" Value="True"></asp:ListItem> 
                   </asp:DropDownList> 
                   <asp:HiddenField ID="hdStatus" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "status") %>' /> 
                </EditItemTemplate> 
This just selects the status dropdown value coming from database.
I want that when i update the record using AllowAutomaticUpdates="True"   it should pick dropdown value ie if i selected Pending then it shoul pick False else True(which is value field of dropdown) 
0
Tsvetoslav
Telerik team
answered on 29 Jan 2010, 11:22 AM
Hello Amarinder,

Have you set AllowAutomaticUpdates=true for the MasterTableView or the grid?

Sincerely yours,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amarinder Singh
Top achievements
Rank 1
answered on 29 Jan 2010, 11:42 AM
Yes that i had mentioned in my previous post. When i click update my all data is updated except the dropdown data which i selected.
0
Tsvetoslav
Telerik team
answered on 04 Feb 2010, 09:19 AM
Hello Amarinder,

 Please, open up a formal support ticket and send us a small test project - we shall debug it and provide you with a solution.

Thank you.

Greetings,
Tsvetoslav
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
Amarinder Singh
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Amarinder Singh
Top achievements
Rank 1
Share this question
or