Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update DB From a Drop Down within a Grid View , ASP.NET

Posted on 2009-07-08
7
Medium Priority
?
280 Views
Last Modified: 2012-05-07
Hello,
I have one ASP.NET Grid view GV1, containing one template field. "Reason"
in the Edit Item Template, i have one Drop Down DD1, and i want that when the user hits edit, to be able to choose a value from the DD, which will be updated in the underlying Data Base.

The DD1, is not data bound, it has list items.
Now when i am updating from the GV1, a null value is going to the DB.

How can i make only one selected value from the DD1, updatable in the DB?
thanks

<asp:TemplateField HeaderText="Reason">
                <EditItemTemplate>
                    <asp:DropDownList ID="DD1" runat="server" 
                        Font-Names="Cambria" Font-Size="8pt"  >
                        <asp:ListItem>R1</asp:ListItem>
                        <asp:ListItem>R2</asp:ListItem>
                        <asp:ListItem>R3</asp:ListItem>
                        <asp:ListItem>R4</asp:ListItem>
                        <asp:ListItem>Other</asp:ListItem>
                    </asp:DropDownList>  
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("AppReas") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

Open in new window

0
Comment
Question by:Nyana22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24804695
So whatever you select...and click update...it is passing null value ...right?

Can you also share your dataSource code...also any relevant code from your code-behind.
0
 

Author Comment

by:Nyana22
ID: 24804783
Yes Sami, That true,
For display :
There is a stored procedure to select data from 2 tables,
For update
also a SP to update one table.

There is one class containing 2 functions, one for selection, one for the update,
The update function has all the GV field as parameter.

There is no Code behind.

Also,
the update statement in the DB finds a record in the update table by to fields, because the combinaison is the key. This same combination i set it to DataKeys name of the GV.

And i also bound the 2 key field from the data source to the grid view, but i set their visible propriety to False.

The update function in the DAL, is a simple call to the SP, using ADO class,
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24804888
So you are using ObjectDataSource to do this update ? if so can you share the markup ..
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Nyana22
ID: 24804940
yes i do use an ODS, and here is the markup,
By the way, in the GV, i have only one bound field, and all the other are template.

The user need to update or the bound field or this template containing the DD.

I tried to update the bound field , and its working good.
    <asp:ObjectDataSource ID="getDetailODS" runat="server" SelectMethod="getCountDetail"
        TypeName="CountDiscAL" UpdateMethod="upCountDetail">
        <SelectParameters>
            <asp:Parameter DefaultValue="2" Name="CountNo" Type="Int32" />
            <asp:Parameter Name="onlyDisc" Type="String" />
            <asp:Parameter Name="ifApp" Type="String" />
            <asp:Parameter Name="ifCorr" Type="String" />
            <asp:Parameter Name="itemSrch" Type="String" />
            <asp:Parameter Name="descSrch" Type="String" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="itemNo" Type="String" />
            <asp:Parameter Name="itemDesc" Type="String" />
            <asp:Parameter Name="PhysicalCount" Type="Decimal" />
            <asp:Parameter Name="MaxCurrent" Type="Decimal" />
            <asp:Parameter Name="Discrepency" Type="Decimal" />
            <asp:Parameter Name="dApproved" Type="String" />
            <asp:Parameter Name="AppReas" Type="String" />
            <asp:Parameter Name="dCorrected" Type="Int32" />
            <asp:Parameter Name="pCountID" Type="Int32" />
            <asp:Parameter Name="itemWarPK" Type="Int32" />
        </UpdateParameters>
    </asp:ObjectDataSource>

Open in new window

0
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 24805919
Try this:
1: Remove <asp:Parameter Name="AppReas" Type="String" />
from your UpdateParameters list
2: Add this parameter to the collection in your GV RowUpdating event handler like below:

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    Dim ddl As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("DD1"), DropDownList)
    SqlDataSource1.UpdateParameters.Add("Age", ddl.SelectedValue)
End Sub
0
 

Author Comment

by:Nyana22
ID: 24806272
thanks,
it worked, but what's all that about?
i appreciate some clarification,
thanks
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24806324
looks since your DDL is not Databounded you parameter was never assigned the value from the DDL implicitly
what the code does is assign the ddl selected value to the parameter explicitly like:
  SqlDataSource1.UpdateParameters.Add("Age", ddl.SelectedValue)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question