467,923 Members | 1,392 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

Using listview datakeyname for listbox parameter

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 objectdatasource 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
  • viewed: 4402
Share:
5 Replies
tlhintoq
Expert 2GB
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 myEmployeeObject.PersonnelNumber;

If you want to return the entire EmployeeObject, then change your return type from a SqlInt32 to an EmployeeObject type.... return myEmployeeObject;
May 2 '09 #2
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
[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
Expert 2GB
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
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 objectdatasource 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

Post your reply

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

Similar topics

4 posts views Thread by Mr. B | last post: by
2 posts views Thread by Aron Henning | last post: by
2 posts views Thread by farmer | last post: by
2 posts views Thread by markliam | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.