Click here to Skip to main content
15,885,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want insert only 10 records in my table. And I want to display those records in my gridview and when I suppose to insert 11 th record in gridview .Thern it has to Give error like Only 10 records is allowed.
Posted
Comments
syed shanu 17-Mar-14 0:47am    
You question is not clear.If you want to display only 10 recoudes from DB then you can query to select top 10 record from your db and dind to grid.If you want to insert means if you want to add 10 row in button click each time in button click check for the grid row count if its less then 10 then add row else show message.What is your question clear it
Sai Prasad anumolu 17-Mar-14 1:01am    
i need to display only records .After 11 th record is not display in gird view or any other database condition
Peter Leow 17-Mar-14 1:11am    
Do you mean : User can add new rows in the gridview programmatically but not more that 10 rows?
Sai Prasad anumolu 17-Mar-14 1:13am    
yes sir ,
VICK 17-Mar-14 2:19am    
How the data is binding to gridview?? from Database or from a form, from where you are inserting records one by one??

While inserting the records, check the count using the SQL COUNT()[^].

If that is 10, then show error message.
 
Share this answer
 
Comments
Sai Prasad anumolu 17-Mar-14 1:01am    
i need to display only records .After 11 th record is not display in gird view or any other database condition ...
I don't get you. Can you explain again?
Sai Prasad anumolu 17-Mar-14 1:05am    
First Of all , I will display in gridview only 10 records after 11th record is not accepted in grid view. Okey .
Any Code ..I will be use gridview condition or any database logic also
If you are showing 10 records in GridView, then you already know the count, right?
While inserting just check the GridView Rows Count. If it is 10, then show error message. That's it.
Sai Prasad anumolu 17-Mar-14 1:10am    
Yes exactly , After 11 th record in not Accepted in gridview
Based on OP's Comment,

Quote:
Yes ..Its working, Exacting you answer is write but also need in database also only 10 records accepting ..tell me any suggestion
Sai Prasad anumolu



C#
SqlCommand cmd = new SqlCommand("Select top 10 *from Tbl_TextAdds", con);


try this to get only 10 records from the database and bind it to gridview.

Check and share your findings.


:)


EDIT: For OP's another requirement i.e Limit table rows.
You have to trigger the table using the link below.

Possible solution can be found HERE.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900