|
Dont you think using PagedDataSource can make life easier for you in this regard (Of course if you want to do this manually not using DataPager)
|
|
|
|
|
Hi! but i would like to show something like
Total count: X and Page 1 of 7
how do I get above done using pagedatasource class as i have only seen previous next button only
thank you for your help!
|
|
|
|
|
Yes you will get the CurrentPageIndex , CountofPages , Nos of items in a single page etc from the object.
Use
PageSize = No of rows each page will contain (You need to set this)
PageCount = No of Pages.
CurrentPageIndex = Page that is called for.
etc.
uglyeyes wrote: Total count: X and Page 1 of 7
Hey, if this is what you require, why do you need to build a custom html using PageDataSource , rather use DataPager control. It is easier to build these using <asp:DataPager
Check this :
http://msdn.microsoft.com/en-us/library/cc295263(Expression.30).aspx[^]
|
|
|
|
|
Please use the pre tags when posting code.
Most people here will ignore the post if it isn't properly formatted.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
My users table is that:
CREATE TABLE Users(
ID_Users INT IDENTITY(1,1),
Username VARCHAR(30) UNIQUE,
Password VARCHAR(100) DEFAULT 'password',
Nivel tinyint DEFAULT '3',
PRIMARY KEY(ID_Users));
When users give username and password executes the following code:
string sqlUserName;
sqlUserName = "SELECT ID_Users, Username,Password,Nivel FROM Users ";
sqlUserName += " WHERE (Username ='" + UserName + "')";
sqlUserName += " AND (Password ='" + Password + "')";
SqlCommand com = new SqlCommand(sqlUserName, Conn);
string existe;
existe = (string)com.ExecuteScalar();
if (existe != null)
(...)
The problem is, I added five minutes ago "SELECT ID_Users". Now I have the error: "unable to cast int32 to string".
I dont understand, because I use sucessfuly tinyint and there is no problem. Ok, its not a int32, but in the end its not the same thing? What should I do ?
EDIT: looks like if I do:
object existe;
existe = com.ExecuteScalar();
There's no error. Can I use it with no problem's ?
|
|
|
|
|
To make you understand, I guess ExecuteScalar executes a query and returns only the first column of the first row. All others are just ignored. So why do you select them ??
Anyways, ExecuteScalar returns an object. So you might use
string existe = com.ExecuteScalar().ToString();
But let me remind you, if there is no row selected, this line will through an error. So rather check the object first.
object result = com.ExecuteScalar();
if(result != null)
string existe = result.ToString();
Hope this is fine. Or you can also check Count(*) to determine if anyone is selected or not in the query.
|
|
|
|
|
Why are you trying to use a string as a boolean?
The more acceptable way to handle this would...
SELECT CASE COUNT(*) WHEN 0 THEN 0 ELSE 1 END
FROM Users WHERE Username...
return Convert.ToBoolean(cmd.ExecuteScalar());
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Check the last line.. I think I have already mentioned that.. .
I think the author wants to use the UserID or the data that is selected. So he wrote like this.
|
|
|
|
|
Abhishek Sur wrote: So he wrote like this
This doesn't lessen our responsibility to also point out misunderstandings and mistakes in usage and give guidance on more correct ways of implementation.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Because I also use SqlDataReader
I will use object, I think in this case is the best choice for me
Many thanks for all your help!
|
|
|
|
|
Maxdd 7 wrote: Many thanks for all your help!
You are most welcome bro...
Cheers.
|
|
|
|
|
Maxdd 7 wrote: Because I also use SqlDataReader
That has nothing to do with it. DataReader provides methods such as GetString, GetInt, GetBoolean. Learning to use the tools properly will be a great benefit to you in the future.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I was just answering to this question:
"
To make you understand, I guess ExecuteScalar executes a query and returns only the first column of the first row. All others are just ignored. So why do you select them ?? "
I use SqlData reader (I erased those lines on first post here) so I can extract those values.
|
|
|
|
|
See other reply for a more acceptable way to handle this.
Also, you should be strongly encouraged to not use inline SQL or at the very least use a parameterized query. Search Google for SQL Injection attack.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: you should be strongly encouraged to not use inline SQL or at the very least use a parameterized query.
I accept with you in this regard.
|
|
|
|
|
where do username and password come from ? Does the user input them ? If they do, this is terrible code. Even if they don't, it is not great.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I've a user control, which contains GridView. The gridview is bound to the ObjectDataSource. The gridview is displaying checkboxes in the shape of matrix like below
Title | View | Insert | Edit | Users | checkbox | checkbox | checkbox | Page Data | checkbox | checkbox | checkbox |
The columns and Titles are dynamic, which is generated by the object(which is used by ObjectDataSource). The data of the grid is displayed correctly without any problem. Under the grid there is button. On the button click I want to know, which check boxes are checked. I can loop through every row of the grid and can access the checkbox also.
Now, problem is, on button click when I am looping through gridview rows, all checkboxes are shown as unchecked while before click I check some checkboxes.
Strange behavior is this, that, on 1st click, checkboxes are not retaining checked state, while on 2nd click, same code shows checked check boxes correctly.
In short, problem is on 1st click, while subsequent clicks are working as expected. Is there anybody who can tell whats wrong?
Regards
Aftab Sindhi
.NET Application Developer
U.A.E
|
|
|
|
|
Aftab Sindhi wrote: In short, problem is on 1st click, while subsequent clicks are working as expected.
Just Debug the code.
Everything Is Possible!
|
|
|
|
|
hello
what is the difference between httpwebrequest,httpwebresponse and webrequest,webresponse
in asp.net and what do they use for
|
|
|
|
|
HttpRequest / HttpResponse classes are derived from WebRequest and WebResponse classes which can handles only Http request and response.
The method WebRequest.Create returns appropriate object based on the url passed. Say you pass
http://www.google.com
The create factory method will then produce HttpWebRequest object as Http protocol is used. On the other hand if you use Ftp urls it will produce FtpWebRequest object.So we write :
HttpWebRequest req = WebRequest.Create("http://www.google.com") as HttpWebRequest;
If you are not sure about the url passed, you can easily use WebRequest class.
|
|
|
|
|
can we store viewstate in masterpage. so that when a user tries to open a new tab, the id is fetched from the viewstate.
Everything Is Possible!
|
|
|
|
|
Suresh Dayma wrote: can we store viewstate in masterpage.
I didn't get your question. What do you mean by store view state in master page. I would suggest you to have a qucik look into Beginner's Guide To View State [^]article, and let me know if you have any more issue.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Thanks for your reply.
ok, just take an example
this is what i want
in masterpage, i have created a label called 'customer name'.
and fetched the customer name from the database and assigned it to the label. when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database.
(Assume there is a single master page and multipe content pages.)
Everything Is Possible!
|
|
|
|
|
Suresh Dayma wrote: when i navigate from one page to another then, I just want to retain the customer name across multiple pages without having to interact with the database.
For that you need to use Session insted of ViewState. Fetch the data first time from DB and put it into session. Now you can access them any where from your site.
Following code is used for storing a value to session
Collapse
Session["CustomerName"] = dbUserName;
Now, let see how we can retrieve values from Session
Collapse
if (Session["CustomerName"] != null)
{
lblWelcome.Text = "Welcome : " + Session["CustomerName"];
}
else
{
}
Hope this will help you. If you want to know more about the session, please read this one : Exploring Session in ASP.Net[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Currently, i have used the sessions to store this.
but when the user tries to open it in a new tab then this does not work.
Example
I have a gridview having multiple customers.
if i open multiple customer details on multiple tabs then it will overwrite the customer details.
so it does not make sense to store customer details in Session.
Everything Is Possible!
|
|
|
|