Using a multiselect listbox to populate a datagrid

 Hi,

I'm pretty new to vb.net and am trying to develop a website for a school project.

 I am using a dataset (xsd file) and have a query that populates a listbox with multiselect enabled.

When I click an item, it shows my datagrid correctly, but i cant get it to work with the multiselect.

I tried doing something like the below code to get it to 'filter' using multiple selections.  I also set the Onfiltering tag for the datasource, but alas i get this error when selecting 2 fields "Cannot perform '=' operation on System.Int32 and System.String."

 

 

1        Protected Sub QuestionDataSource_Filtering(ByVal sender As Object, ByVal e As ObjectDataSourceFilteringEventArgs)
2            Dim exp As String = String.Empty
3            For Each item As ListItem In ddlTopic.Items
4                If item.Selected Then
5                    If exp <> String.Empty Then
6                        exp += " , "
7                    End If
8                    exp += CStr(item.Value)
9                End If
10           Next
11   
12           exp = "TopicID IN ('" + exp + "')"
13           e.ParameterValues.Clear()
14           e.ParameterValues.Add("TopicID", exp)
15   
16           If exp <> String.Empty Then
17               QuestionDataSource.FilterExpression = exp
18   
19           End If
20       End Sub
 
 Here is my query for my table adapter :
 SELECT     Questions.QuestionsID, LTRIM(RTRIM(Questions.UserID)) AS UserID, Questions.Description, Questions.Number, LTRIM(RTRIM(Questions.FileName)) 
AS FileName, Questions.Complexity, LTRIM(RTRIM(Questions.FilePath)) AS FilePath, Questions.Answer, Questions.QuestionDate,
LTRIM(RTRIM(Contributor.LastName)) + ', ' + LTRIM(RTRIM(Contributor.FirstName)) AS Author, 'mailto:' + LTRIM(RTRIM(Contributor.Email)) AS Email,
TopicQuestions.TopicID
FROM Questions INNER JOIN
Contributor ON Questions.UserID = Contributor.UserID INNER JOIN
TopicQuestions ON Questions.QuestionsID = TopicQuestions.QuestionsID
WHERE TopicQuestions.TopicID = @TopicID
 
 
Any help would be great.  Thanks 
  
0
r91087
5/5/2009 1:33:30 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
1183 Views

Similar Articles

[PageSpeed] 3

 Yes when u are using the In operator IN for the query..

ur string has to look like  this IN('1','2','3') wher as ur string xurrently may look lik this IN( 1,2,3)

this is jus a suggestiong can u try this

 

 If exp &lt;&gt; String.Empty Then
6 exp = "'" exp "'" + " , "
7 End If

 


Please mark as answer if it helped u!
0
kavita_khandhadia
5/5/2009 5:32:26 AM
Reply:

Similar Artilces:

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

Multiselection Listbox to Populate SQL Db using C#
As a newbie to C# and webforms, I'm creating simple application that stores log files to a SQL database: date/time, action, admin_name, server_id. The problem is with the server name/id field. I have a multiselection listbox that successfully populates my entries (server 1, server 2, server 3, etc.) and I can get it to commit a row to the db if I've selected the topmost value in the server field. I don't know how to create a counter so that I can create a row for each of server that has been selected.Thanks in advance!First the page_load stuff....private void Page_Load(object sender, System....

Populating with code a DropDownList used as an editing control in a Datagrid
I want to use a dropdownlist in an editing DataGrid, but want to specify in my code what the listed values should be. The dropdownlist is to show the values "High", "Normal", and "Low". Can't figure out how to do this. Can't stuff in values in the edititemtemplate declaration of the control, and can't add items in my code upstream as the control doesn't yet exist. I was hoping to be able to do this rather than have to create another table in my database with just these 3 values create a dataset for that table and bind to that. Seems like that would be overkil...

Populating textbox using calendar in DETAILSVIEW control
I need help. I am a new member, though I have used your site for a while now. I have read alot about popup calendars but have not find anything that is specifically geared towards DetailsView controls.  I borrows the following codes. Instead of adding the textbox on a form I added it in a templatefield (detailsview instead). Every time I click on the textbox I get this message "HTTP Error 404 - Not found version information: ASP.NET Development Server 8.0.0.0. I need to make my textbox a required field too. Thank you in advance for all your help. This is my code for the detailsvi...

populate Grid view control through programming using Ado.net
i am working in visual studio 2005 .i want to populate Grid view control  through programming using Ado.net  with result of datareader ,gridview is already filled with a datasource control but there is an error " Index is out of Rang And Index cant negative" plz any one help me Code is : GrdManageMessages.DataSourceID = ""GrdManageMessages.DataBind()  Dim i As Integer = 0Dim SqlConnect As SqlConnection = New SqlConnection("Data Source=COMMANDER\SQLEXPRESS;Initial Catalog=Enotice;Integrated Security=True")      &n...

DataGrid etc does not display when using VS.NET server controls
This thing is driving me nuts! I know you should be able to do it with code but I want to be able to drag a dataadapter onto a page, set up the dataset from that and bind it to a datagrid without writing a line of code. Everytime I do it whether I am using a remote SQL Server or a local MSDE for the datasouce all I get is a blank page. The source contains the form and the __VIEWSTATE and that is it. If I add in the pageload codebehind datagrid1.databind() then I get the column headings and that is all. Any ideas? Regards, DaveB You always have to call DataBind, that's for sure....

Populating a ListBox from a database using VB.NET 1.1
Hi, I've been racking my brain trying to do a simple task of populating a listbox from a table in a sqlserver database. From trawling the web I have found that nearly all examples show population of the listbox via an array. Also they show you need to databind the listbox. However the only attribute I can find is databindings. What I have managed to get working is the listbox text to be populated but not the value. (SEE CODE BELOW). I've spent 2 days trying to solve it and am thinking of giving up rewritting the whole project in C# which is what I code in normaly anyway. ...

What control do I use (or do I not use a control at all...)
Okay so here's the story so far. I am making a blog to be incorporated into a website. Well, I'm doing the blog from scratch. I'm using MySQL to source all the data via MySQL .NET/Connector. Now while developing the script, I used DataReader and Response.Write to show the blog topics. Now that it has come to put it under a design (I'm using a Master Page for that), I've hit the problem. Response.Write shows all the topics before any of the design elements could be incorporated. So that (more or less) is out of question. So next I looked into the data presentation controls. I looked up GridVi...

nested datagrid--trouble using value from parent datagrid to populate nested datagrid
Hi all,I am having trouble nesting two datagrids.  The master one populates correctly.  The other one gets a value from the master datagrid and should populate based on it's value.  It's value determines whether the customer ordered a package deal...the child datagrid would list out all the items in the package deal (something like the below, the green is the master, the yellow is the child stuff):family package deal 1    1 movie    2 buckets of popcorn    4 small sodas    1 pk sour patch kidsI am getting this error:T...

Populating a listBox (i.e. <select><option>) from DB using VB.NET
_/_/_/_/_/_/_/_/_/_/_/ _/_/_/_/_/_/_/_/_/_/ _/_/_______/_/_/_/ Hi every one! I am trying to populate a listbox using VB.NET. I am using SQL Server 2000, and the database looks like this: (sport prefixes) Table name: Prefixes ID Prefix ----- ----------- 1 FTBL 2 SCCR 3 TNNS 4 HCKY .... ... There's a list (i.e. <select><option>) on the web form and its id=Prefixes_list. The list is in a .ascx file, and the code for populating...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

ajax.net controls used in custom composite controls?
I am creating an events calendar that uses the accordion to display the events for the selected day.  The problem I'm having is that the accordion is not responding to any client side events.  I would really like to find a good "How to" article for building composite controls that incorporate an ajax.net control like the accordion....

using a .Net Control as activex control in VCL form
Hi , We have a to integrate a simple .Dot CSharp control which needs to be integrated into bcb2010 VCL form as a control. We will place the control on the VCL form along with other VCL controls's. I tried creating a simple .net control using a lable+textbox and trying to use in vcl form. I have made the assembly comvisible and generated tlb files and .bpl for the component. I could see the component in "ActiveX" tool palette. But when I drag the object onto VCL form and try to access its attributes I run into problems. I am not able to see .net control on the vcl at runti...

Unable to use Custom Control within a datagrid control
I have a datagrid and a template field to look like this <asp:TemplateField> <ItemTemplate> <customControl:Display runat="server" Description='<%#DataBinder.Eval(Container.DataItem,"Description")%>' /> <asp:Label ID="mylabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ReportID")%>' /> </ItemTemplate> </asp:TemplateField> My custom control has a property called "Description" which basically is nothing but the value for a label in that control. Now, in the above code, the asp label control correctly displays the text,...

Web resources about - Using a multiselect listbox to populate a datagrid - asp.net.presentation-controls

Using Backbone to improve multiselects
Sometimes you need to ask a users for multiple answers to a single question. But what’s the best way to go about it? Checkbox-field A multiselect ...

n7player Music Player with 10-band Equalizer on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about n7player Music Player with 10-band Equalizer. Download n7player ...

Recently Active 'twitter-bootstrap' Questions - Stack Overflow
current community chat blog Stack Overflow Meta Stack Overflow Stack Overflow Careers your communities Sign up or log in to customize your list. ...

Menu bar - Wikipedia, the free encyclopedia
A menu bar is a region of a screen or application interface where drop down menus are displayed. The menu bar's purpose is to supply a common ...

40个Bootstrap的扩展和插件集合
设计创意1984是一个关于创意设计,设计,插画,艺术摄影,lomo,素材,教程,web,灵感来源,平面设计欣赏的综合性网站。站点每日更新原创文章,为设计师提供优美高品质图片和创意灵感来源。

cr2-Thumbnailer Demo - Android-Apps auf Google Play
An explorer-like application to preview Canon (c) DSLR RAW-Files. View, share and save the embedded jpeg-images. Fullscreen view to switch thru ...

Browse, play and organize your movie files with Saleen Video Manager
... but double-clicking any of those frames starts playing the file at that point a real time-saver. Organizing your collection is simple. Multiselect ...

Bytes - IT + Developer Community - Connect with IT Pros
Bytes.com is a community for Developers and IT Professionals. Join 414,150 members and discuss topics such as software development, networking, ...

Chrome Experiments - "SVG Editor" by inEvo.pt
... lines, diamonds, etc.. You can turn off this feature using the check box. - Elements selection, move, rotate, scale. Press Control to multiselect ...

Facebook Camera app really, really wants to know your location
Facebook's slick new camera app goes on strike if you don't give it access to your location. Here's why. Read this blog post by Eric Mack on ...

Resources last updated: 1/19/2016 5:00:31 AM