Showing posts with label couldnt. Show all posts
Showing posts with label couldnt. Show all posts

Thursday, March 29, 2012

Filter by parameter value

Is this possible? I searched and couldnt find a solution that would
allow me to filter my results by a paramter value that I want the user
to be able to enter. My filtering works fine when entering in a numeric
value in manually but not when running it by the parameter. I get the
following error message: 'Fail to Evaluate
FilterExpression/FilterValues'Most likely the data types of the filter expression and the filter value
expression don't match.
Please try something similar to this:
Filter expression:
=CInt(Fields!SomeField.Value)
Filter value expression:
=CInt(Parameters!SomeParameter.Value)
The important part is the CInt() function call which will ensure that you
are comparing values of identical data types. More information on data type
conversion functions can be found on MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vagrptypeconversion.asp
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Brent" <Brent.Raymond@.gmail.com> wrote in message
news:1126284534.290617.315760@.g14g2000cwa.googlegroups.com...
> Is this possible? I searched and couldnt find a solution that would
> allow me to filter my results by a paramter value that I want the user
> to be able to enter. My filtering works fine when entering in a numeric
> value in manually but not when running it by the parameter. I get the
> following error message: 'Fail to Evaluate
> FilterExpression/FilterValues'
>

Tuesday, March 27, 2012

filling gridview from code

hello, i'd need a little help with filling GridViews

i browsed over like 10 search pages, but couldnt find any which would solve my problem.

so in my ajax project i made a testing page pulled a gridview (GridView1) on it with a fhew buttons and textboxes.
i need to fill the gv from code so my websie.asp.cs looks like this

 
1protected void Page_Load(object sender, EventArgs e)
2 {
3
4
5string connstr ="Data Source=.;database=teszt;user id=user;password=pass";
6 SqlConnection conn =new SqlConnection(connstr);
7 SqlCommand comm =new SqlCommand("select * from users", conn);
8 conn.Open();
9 SqlDataReader reader;
10 reader = comm.ExecuteReader();
11if (reader.HasRows)
12 {
13 GridView1.DataSource = reader;
14 GridView1.DataBind();
15 }
16 reader.Close();
17 conn.Close();
18 comm.Dispose();
19 }

so i load the page and there's no gridview on the page at all, nor an error msg, the connection and the database/table is fine.
any suggestions on what am i doing wrong? and i also like to know if there would be any problem with using this on a tabcontrol/tab
thankyou 


you have bind the data reader.

you have to bind the datasource like datatable or dataset or some list or collection.

That's the problem why you didn't see the grid data.

|||

ahh yes thankyou, i knwer there was smething wrong with that, so i managed the code from msdn, tho the GridView needs to be set to generate cols true

1protected void Page_Load(object sender, EventArgs e)
2 {
3// This example uses Microsoft SQL Server and connects
4 // to the Northwind sample database. The data source needs
5 // to be bound to the GridView control only when the
6 // page is first loaded. Thereafter, the values are
7 // stored in view state.
8if(!IsPostBack)
9 {
10
11// Declare the query string.
12 String queryString =
13"Select * From [users]";
14
15// Run the query and bind the resulting DataSet
16 // to the GridView control.
17 DataSet ds = GetData(queryString);
18if (ds.Tables.Count > 0)
19 {
20 GridView1.DataSource = ds;
21 GridView1.DataBind();
22 }
23else
24 {
25 Response.Write("Unable to connect to the database.");
26 }
27
28 }
29
30 }
31
32 DataSet GetData(String queryString)
33 {
34
35// Retrieve the connection string stored in the Web.config file.
36 String connectionString ="Data Source=.;database=teszt;user id=user;password=pass";
37
38 DataSet ds =new DataSet();
39
40try
41 {
42// Connect to the database and run the query.
43 SqlConnection connection =new SqlConnection(connectionString);
44 SqlDataAdapter adapter =new SqlDataAdapter(queryString, connection);
45
46// Fill the DataSet.
47 adapter.Fill(ds);
48
49 }
50catch(Exception ex)
51 {
52
53// The connection failed. Display an error message.
54 Response.Write("Unable to connect to the database.");
55
56 }
57
58return ds;
|||

one more thing tho, on this page i have a hidden table which contains 2 textboxes and a button, this visibility is also controlled by a button.
so the input fields are for inserting data to the table which the gridview is showing and when i hit the button to execute the insert i want the gridview to be updated so i put a GridView1.DataBind() in my input buttons final things to do, but what happens is after the postback the gridview is gonne. now what is up with that? does it forget its source?