using the update feature included with GridView edit, drop down list value being lost

I've got a GridView populated with data from datasource A. One of the columns is a user name, stored in table A. There's also a list of user names in table b. What I'd like to accomplish is to enter into edit view on the GridView, select a new user name from a drop down list, click update on the GridView row and HAVE IT ACTUALLY UPDATE! The examples I have been able to find seem to stop the example without clicking update! When I click update, the data field on table A is blanked out. I know it has something to do with finding the drop down list control (since it doesn't exist until runtime) in the code behind, but coming from classic asp, C# is still very new to me. Could someone help me out? Thanks!
nickbailey111Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Munawar HussainPrincipal Software EngineerCommented:
you need to add parameter to for new value you want to update
for that go to properties of SqlDataSource and select UpdateQuery .. it will open another window . from there add parameter name and tell from where to get value of parameter.. ie control . form or ... others options.

actually you have not set the parameters for update query hence it just update the table with spaces. which is default for update query

thanks
0
nickbailey111Author Commented:
take a look at the code, try to run it - I get a failure on "e.NewValues.Add("guid", rm.SelectedValue) not being set to an instance of an object.


aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="IDNY_web._Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="guid" DataSourceID="SDS_Cases" 
            onrowupdating="GridView1_RowUpdating">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="guid" HeaderText="guid" 
                    SortExpression="guid" ReadOnly="True" Visible="False" />
                <asp:TemplateField HeaderText="rm_guid" SortExpression="rm_guid">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" 
                            DataSourceID="SqlDataSourceRM" DataTextField="rm_name" DataValueField="guid">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSourceRM" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:IConn %>" 
                            SelectCommand="select * from id_rm"></asp:SqlDataSource>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("rm_guid") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SDS_RMs" runat="server" 
            ConnectionString="<%$ ConnectionStrings:Conn %>" 
            SelectCommand="select * from id_cases" 
            UpdateCommand="update id_Cases set rm_guid=@rm_guid where guid=@guid">
            <UpdateParameters>
                <asp:Parameter Name="rm_guid" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </div>
  </form>
</body>
</html>
 
 
CODE BEHIND:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
 
namespace IDNY_web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
        
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DropDownList rm = (DropDownList)
            (GridView1.Rows[e.RowIndex].FindControl("DDL_RM"));
            e.NewValues.Add("guid", rm.SelectedValue);
        }
    }
}

Open in new window

0
nickbailey111Author Commented:
simple problems- I spotted my error once I posted the code.

1) my drop down list id wasn't DDL_RM as I specified in the findcontrol action
2) mixed up my sql data source names

Thanks all anyway,.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.