Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

insertcommand in a grid getting the name of a dropdown

Posted on 2013-01-23
8
Medium Priority
?
323 Views
Last Modified: 2013-01-28
I am trying to insert the selected value of a dropdown box into the database and I cant get it - anyone know?

            string sqlStr = "";
            int mgrid = user.UserID;
            int selecteduser;
            Control myControl = FindControl("ddlusers");
            if (myControl != null || Convert.ToString(myControl) != "--Please Select--")
            {

                selecteduser = myControl.SelectedValue; <-- selected value doesnot exist 
                
            }
            sqlStr += "Insert Into ManagerStaff (mgruseruid,staffuseruid) Values (mgrid,selecteduser) ";
            using (SqlConnection conn = new SqlConnection(conStr))
            using (SqlCommand cmd = new SqlCommand(sqlStr, conn))
            {
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
            }

Open in new window

0
Comment
Question by:r3nder
[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
  • 5
  • 3
8 Comments
 
LVL 9

Expert Comment

by:psgindiana
ID: 38812092
Error messages, or just no results?
0
 
LVL 6

Author Comment

by:r3nder
ID: 38812103
'System.Web.UI.Control' does not contain a definition for 'SelectedValue' and no extension method 'SelectedValue' accepting a first argument of type 'System.Web.UI.Control' could be found (are you missing a using directive or an assembly reference?)
0
 
LVL 9

Expert Comment

by:psgindiana
ID: 38812145
Try
selecteduser = ((DropDownList)myControl).SelectedValue.ToString();

Open in new window

This will cast the control as a DropDownList, as well as return a string you can use.
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 6

Author Comment

by:r3nder
ID: 38812192
"Object reference not set to an instance of an object."
0
 
LVL 6

Author Comment

by:r3nder
ID: 38812199
here is the asp
 <Columns>
                     <telerik:GridDropDownColumn UniqueName="ddlusers" DataSourceID="UserDD" ListValueField="useruid" ListTextField="username" 
                      HeaderText="Users" Visible="false">
                     </telerik:GridDropDownColumn>

Open in new window

0
 
LVL 9

Assisted Solution

by:psgindiana
psgindiana earned 1500 total points
ID: 38812258
On what line? If you debug, does it even get to line 8 of your original post?

This is not a "DropDownList" it is a telerik specific control called "GridDropDownColumn". You can try replacing "DropDownList" with "GridDropDownColumn" in the cast. Not sure that's your biggest problem, though. Still not sure if your findcontrol is even returning a control.
0
 
LVL 6

Accepted Solution

by:
r3nder earned 0 total points
ID: 38812330
GridEditableItem item = e.Item as GridEditableItem;

                selecteduser = Convert.ToInt32((item["ddlusers"].Controls[0] as RadComboBox).SelectedValue);
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 38826198
Thanks for the info - with your comment I was able to figure it out psgindiana
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

715 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