Using below code you can get Repeater's Row/Item Count:
in below code "Container.ItemIndex" is used to get current row number and
"(string[])rpttags.DataSource).Length" is used to get total row/item count.
in above line my datasource for repeater was a string array so i used string[] as datasourcetype and used length to get its count in same way you can get for all other types
While working on a project which has huge database interaction and i was using stored procedure to get good performance. But even though i was using stored procedure the performance was not so good all the time. I mean it was not consistent, for few queries on same stored procedure it was so good and some times it was going worst.
I have done lots of google for it and finally i got the solution.. The easiest solution which you can apply to any existing stored procedure without doing any major changes in it..
Its mostly helpful in situation where you have a stored procedure and the amount of data returned is varying wildly depending on what parameters are passed in.
Some time you will see that the performance of stored procedure change dramatically depending on how much data is being returned.
Then you could be a victim of SQL Server Parameter sniffing.
[YOU ARE AT RIGHT PLACE TO GET SOLUTION]
Normally we writes procedure like:
CREATE PROCEDURE GetUserData
@UserName nvarchar(20)
AS
BEGIN
SELECT DisplayName, FirstName, LastName
FROM dbo.User
WHERE UserName = @UserName
END
Now to get good speed constantly, just do some minor changes in it:
CREATE PROCEDURE GetUserData
@UserName nvarchar(20)
AS
BEGIN
DECLARE @myUserName nvarchar(20)
SET @myUserName = @UserName
SELECT DisplayName, FirstName, LastName
FROM dbo.User
WHERE UserName = @myUserName
END
I have done some minor changes in it.
that is, i have just declared local variables and assigned the values of parameters in it and then used those variables in queries instead of using parameters directly.
Now You must be thinking that how come it affect the performance.
Let me explain:
Here is the Microsoft definition:
“Parameter sniffing” refers to a process whereby SQL Server’s execution environment “sniffs” the current parameter values during compilation or recompilation, and passes it along to the query optimizer so that they can be used to generate potentially faster query execution plans. The word “current” refers to the parameter values present in the statement call that caused a compilation or a recompilation.
So For some strange reason, when you pass the parameters (@UserName in this case) to a local variable (@myUserName) SQL Server will no longer use the value of the parameter (@UserName) to influence the query plan and you will get the performance constantly. :)
To show multiple jquery scroller in single page just add an extra div on outer side or every scroller. means place every scroller in seperate div and its done..
The fact is that dictionary is a hashtable.
The main difference is that dictionary is a hashtable where as hashtable is not.
That means you get type safety with Dictionary, because you can't insert any random object into it, and you don't have to cast the values you take out.
its almost similar what difference between array list and generic list.
XmlDataSource class internally calls a private method called CreateCacheKey. Now, if you are using XmlDataSource without an ID, after upgrading the solution to ASP.NET 3.5, this might throw an exception - "When caching is enabled for the XmlDataSource that is not in the pages control tree it requires a UniqueID that is unique throughout the application." This is due to the absence of the UniqueID (which is read-only, but my experiment shows that setting the ID handles the same), which is used as part of the caching key, without which all instances would try to use same caching key. Setting a distinct ID solves this problem and the problem goes away
eg:
XmlDataSource XmlSrc = new XmlDataSource();
XmlSrc.ID = "someid";
We all know how to get value from xml file in .net but we face issue when there is a namespace with that xml file.
When a xml file contains a namespace then you will have to do some extra efforts to retrieve its value.
Lets say my xml is like:
Videos119150207463somepathsometitle
somelink
...
http://someurl/standard-and-poors-india-connection/207463
Tue, 09 Aug 2011 6:26:48 IST1312894608
Now i wants to access value of "url" attribute of "media:thumbnail" tag, so to get it you will have to do :
Dim path As String = "http://api.flickr.com/services/feeds/photoset.gne?set=72157604607980332&nsid=51374889@N00&lang=en-us&format=rss_200_enc"
Dim xmldoc As New XmlDocument()
xmldoc.Load(path)
Dim xnm As New XmlNamespaceManager(xmldoc.NameTable)
xnm.AddNamespace("media", "http://search.yahoo.com/mrss/")
Dim nList As XmlNodeList = xmldoc.SelectNodes("//item/media:thumbnail/@url", xnm)
For Each xNode As XmlNode In nList
ListBox1.Items.Add(xNode.InnerText)
TextBox1.Text += TextBox1.Text + xNode.InnerText + vbNewLine
Next
Now comes to original problem for which i have done google for 2-3 hours and then finally i got the answer.
Problem: I have got a repeater and i wants to show this xml values in it. now 1 option is that you can convert it to a datatable and easily use it.. but it will be extra process to you application. so now we wants to show xml directly to the repeater... to do so see below code:
In code behind file:
XmlDataSource xds = new XmlDataSource();
xds.XPath = "rss/channel/item";
xds.DataFile = sourceXml;// you can write xml path here.
myrpt.DataSource = xds;
myrpt.DataBind();
Now in .aspx file write below code:
< asp:Repeater ID="myrpt" runat="server" >
< ItemTemplate >
< li >
< div class="multi_div" >
< img src='< %#XPath("*[local-name()='thumbnail' and namespace-uri()='http://search.yahoo.com/mrss/']/@url")% >' class="imgbdr" / >< div class="multi_blkstrip" >
< p class="float_l" >
< img src="images/video_icon.gif" / >< /p >
< p class="float_r" >
< %#XPath("title")% >< /p >
< /div >
< /div >
< p class="vidcap" >
< a href="#" class="fn fl" >< %#XPath("title")% >< /a >< /p >
< /li >
< /ItemTemplate >
< /asp:Repeater >
so this is the main line (solution):
< %#XPath("*[local-name()='thumbnail' and namespace-uri()='http://search.yahoo.com/mrss/']/@url")% >'