Monthly Archives: November 2011
In my previous post I have discussed about how to auto-generate serial no. in a GridView. Extending my previous post, here I am just discussing the same thing for DataList and Repeater controls. I have used DataItemIndex to generate serial no for GridView, which you can find here(http://tiny.cc/f04y7). Now, we can’t use DataItemIndex for DataList or, a Repeater control. For them there is another property called ItemIndex , which will show the anticipated result. ItemIndex is the index number of the DataListItem in the Items collection and index number of the item in the Repeater control in the Items collection. Below is the syntax for ItemIndex-
<ItemTemplate> <%#Container.ItemIndex+1 %> </ItemTemplate>
It is showing anticipated result for me. If anybody has any better idea then please share in the comment.
When there was a need to show a serial no in Gridview on selected datasource then I was doing it in query (SQL Server) using ROW_NUMBER OVER() or RANK OVER(). But in the current project I am working on, needs some GridViews to be populated from XML datasource and some from manipulated/modified datatable. To these scenario I also can include another one, when you need to rows to be sorted in some order by allowing sorting in GridView and data of the to sorted from datatable. So, here I added an ItemTemplate to show the incremental Sl no. column. Following is the code for it.
<asp:TemplateField HeaderText="SL"> <ItemTemplate> <asp:Label ID="lblSlNo" runat="server" Text='<%#Container.DataItemIndex+1 %>'></asp:Label> </ItemTemplate> <HeaderStyle HorizontalAlign="Center" Width="30px" /> <ItemStyle HorizontalAlign="Center" Width="30px" /> </asp:TemplateField>
Here the value shown in the Sl no. column will start from the DataItemIndex (which starts from 0)+1 and so on..
Regarding performance, it is faster than former method and is a very convenient way to do so.
Today, I was working on a existing large book library project. I was told to show a HTML report for all the books present on the library and also directed by mentor that only last name to be shown for the author names. But here problem is that the database doesn’t have a specific column which stores last name of a author. So, tried 2-3 ways for this but none of the way succeeded to solve the problem, although all of them were showing correct result ,when the author has a first name and a last name. But, in India most of the people have a middle name also. So, when the proc or, function encountered a name with 1 or more middle name(s) , resulted in wrong data. Thus, finally I arranged the following function which solved my problem.
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
– Author: Suvendu
– Description: gets last name from supplied full name
CREATE FUNCTION [dbo].[GetLastName]
DECLARE @LastName NVARCHAR(30)
SELECT @LastName = RIGHT(@FullName, ISNULL(NULLIF(CHARINDEX(‘ ‘, REVERSE(@FullName))-1, -1),LEN(@FullName)))
Any communication process needs a sender, who sends the message (may be a request) and a receiver, who receives the message sent to him. This communication process may further progresses when the message sent is a request. Then most of the times, the receiver again responds to the request and sends a message (response) back to the other side.
In a web application, client (generally a browser) plays the role of sender and sends the message (usually request for a page) to the server( web server). Then the server processes the request and replies with a message(requested page). For instance, when type www.suvendugiri.com in the address bar of the browser and press ENTER or click on the GO button, it sends a request to the server where the website is hosted. Here the request is to display the default page of my blog. Now after processing the request , server sends the response. Now the page is rendered to the browser in HTML format. This type of communication is termed as client-server communication.
INFORMOTIONS.COM has a nice idea to describe all this: (check below)
” This client/server interaction is a lot like going to a French restaurant. At the restaurant, you (the user) are presented with a menu of choices by the waiter (the client). After making your selections, the waiter takes note of your choices, translates them into French, and presents them to the French chef (the server) in the kitchen. After the chef prepares your meal, the waiter returns with your diner (the results). Hopefully, the waiter returns with the items you selected, but not always; sometimes things get “lost in the translation.” “