473,778 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using listview datakeyname for listbox parameter

11 New Member
I have managed to put a listbox in my listview and have gotten the box to appear but it is empty. I want to click on the Edit link and based on the datakeyname value pass the parameter to the objectdatasourc e to fill the listbox. I'm trying to use IEnumerable and am not getting it. Can someone help with an understandable example. Or another way to do it.

I'm at a loss to what I am to return (see ??? ) and it doesn't like my (SqlInt32 PersonnelNumber ) telling me it can't convert to "SqlInt32? (in my EmployeeObject) " -
Expand|Select|Wrap|Line Numbers
  1. public IEnumerable<AuthorizationObjectClass> GetEmployeeNoAuthorizations(SqlInt32 PersonnelNumber)
  2.         {
  3.             DataSet ds;
  4.             AuthorizationObjectClass auth = new AuthorizationObjectClass();
  5.             try
  6.             {
  7.                 //EmployeeObjectClass Emp = new EmployeeObjectClass();
  8.                 Emp.PersonnelNumber = PersonnelNumber;
  9.                 ds = data.GetNotSelectedAuthorizations(Emp);
  10.                 if (ds.Tables.Count > 0)
  11.                 {
  12.                     auth.AuthorizationID = Convert.ToInt32(ds.Tables[0].Rows[0]["AuthorizationID"]);
  13.                     auth.AuthorizationDefinition = Convert.ToString(ds.Tables[0].Rows[0]["AuthorizationDescription"]);
  14.                 }
  15.             }
  16.             catch (Exception e)
  17.             {
  18.                 Console.WriteLine("{0} Exception caught.", e);
  19.             }
  20.             return  ???? ;
  21.         }
  22.  
  23.  
May 1 '09 #1
5 4756
tlhintoq
3,525 Recognized Expert Specialist
and it doesn't like my (SqlInt32 PersonnelNumber ) telling me it can't convert to "SqlInt32? (in my EmployeeObject) "
I'm guessing the SqlInt32 is a single item from within the Employee object..

If your return type is the SqlInt32, don't try to return the entire employee object: return just the ID number .... return myEmployeeObjec t.PersonnelNumb er;

If you want to return the entire EmployeeObject, then change your return type from a SqlInt32 to an EmployeeObject type.... return myEmployeeObjec t;
May 2 '09 #2
jrobbins
11 New Member
Can someone please tell me how to get a listbox to populate inside a listview when the Edit button is clicked based on either a hidden field or the datakeynames
May 5 '09 #3
jrobbins
11 New Member
[quote]I was able to retrieve my id field; but when I try to bind results to listbox (NOAUTH), my listbox is showing as null and won't allow the binding. Any ideas?

QUOTE]
Expand|Select|Wrap|Line Numbers
  1.   protected void lvSearchResults_ItemEditing(Object sender, ListViewEditEventArgs e)
  2.     {
  3.  
  4.         string id = lvSearchResults.DataKeys[e.NewEditIndex].Value.ToString();
  5.  
  6.         ListViewItem item = lvSearchResults.Items[e.NewEditIndex];
  7.        CoreDataManager lbNoAuth = new CoreDataManager();
  8.  
  9.         DataTable dt = lbNoAuth.GetNotSelectedAuthorizations(id);
  10.  
  11.         ListBox NoAuth = (ListBox)item.FindControl("lbNoAuthorizations");
  12.  
  13.  
  14.         if (dt.Rows.Count > 0)
  15.         {
  16.  
  17.             NoAuth.DataSource = dt;
  18.             NoAuth.DataTextField = dt.Columns[1].ColumnName;
  19.             NoAuth.DataValueField = dt.Columns[0].ColumnName;
May 5 '09 #4
tlhintoq
3,525 Recognized Expert Specialist
I don't do a lot of this stuff, but...

Expand|Select|Wrap|Line Numbers
  1.  
  2. ListBox NoAuth = (ListBox)item.FindControl("lbNoAuthorizations");
  3.  
If the result of your FindControl is null (no matching controls found) then NoAuth would be null.
May 5 '09 #5
jrobbins
11 New Member
I finally figured this after lots of searching. I have a listbox inside my listview. I grab the datakey on the OnItemEditing event in the listview and then pass the objectdatasourc e the datakey as the default parameter.
Expand|Select|Wrap|Line Numbers
  1. protected void lvSearchResults_OnItemEditing(object sender, ListViewEditEventArgs e)
  2.     {
  3.             ListViewItem currentItem = lvSearchResults.Items[e.NewEditIndex];
  4.  
  5.             string id = lvSearchResults.DataKeys[e.NewEditIndex].Value.ToString();
  6.             Response.Write("datakey:  " + id);
  7.             odsNotSelectedAuthorizations.SelectParameters["PersonnelNumber"].DefaultValue = id;
  8.             odsSelectedAuthorizations.SelectParameters["PersonnelNumber"].DefaultValue = id;
  9.     }
May 6 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1847
by: Mr. B | last post by:
VB.net issue here. I've a strange event that I can't seem to figure out... On my Form, I've a TabControl (two Tabs)... On my first tab, I load an Ascii file and dump some info onto my ListView (which is located on my other Tab). Now IF I click on the 2nd Tab... the Info IS to be sorted out - as I've set
2
3380
by: Aron Henning | last post by:
I have a ListView that contains the subfoldes of a local drive. Whan i click on a subfolder the listbox should display the subfolders of this folder instead. the funktion is as follows: private void FolderList_SelectedIndexChanged(object sender, System.EventArgs e) { try
2
5743
by: Matt Sawyer | last post by:
Hi, I'm attempting to do a drag and drop operation from one listbox to another. I have my listboxes setup with SelectionMode = MultiExtended so that I can use the shift key, cntrl key, etc. to make multiple selections. The problem I am having is that when I use the shift key to select a range of items, I first click on one item (item gets highlighted), then, holding down the shift key, I select another item (the range of items gets...
2
9842
by: farmer | last post by:
I need to populate a listbox of other listview with selected listview items.although the following code works perfecty I want to use an Array (for various reasons) for Each ListItem In listview1.ListItems If ListItem.Checked = True Then listbox1.AddItem ListItem.Text next
2
4018
by: murl | last post by:
Im starting on a application that will map fields from an excel file to fields of a sql table for a very small integration project. I have enabled drag and drop on the source listbox, and the form inbetween the 2 listboxes so i can tell when im dragging over the form. Im stuck on when i dragenter into the 2nd listbox, how can i figure out what position their mouse is over, and what item is at that x and y position? If anybody has any...
2
6307
by: Mamatha | last post by:
Hi I have an application with listview.When i click on one button the data will be displayed like this in the listview: colA colB colC ----- ----- ------ nannacom.com 0 0 When i click on another button,i want to display like this
1
14658
by: Melson | last post by:
Hi May I know what is the differences between vb.net listbox and listview. When should I use listbox or listview. Regards Melson
1
8580
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but it doesn't seem to work at all. Below is my ASP.NET page, and further below, my VB.NET method that I am trying to call: <div id="admin-faq" class="page"> <h2>Site FAQs (Frequently Asked Questions)</h2>
2
10647
by: markliam | last post by:
I have a ListBox that is displaying a formatted string based on the contents of a DataSet. The purpose of the listbox is for the user to select an entry to delete, but I'm not sure how to match the listbox entry with the corresponding DataRow. The DataRow contains a unique id, but the id is not displayed in the formatted string that appears in the listbox. Is there a way to associate the id of the DataRow with the Listbox item so I...
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.