How to sort ArrayList
<asp:Button id=’btnAsc’ runat=’server’ Text=’Asc’></asp:Button> <asp:ListBox id=’ListBox1′ runat=’server’></asp:ListBox> <asp:Button id=’btnDesc’ runat=’server’ Text=’Desc’></asp:Button> VB.NET Private Sub Page_Load(sender As Object, e As System.EventArgs) ’ Put user code to initialize the page here Dim arrlist As New ArrayList() arrlist.Add(‘Tips’) arrlist.Add(‘Tricks’) arrlist.Add(‘Code’) arrlist.Add(‘Samples’) ListBox1.DataSource = arrlist ListBox1.DataBind() ViewState(‘AList’) = arrlist End Sub ’Page_Load Private Sub btnAsc_Click(sender As Object, e As System.EventArgs) CType(ViewState(‘AList’), ArrayList).Sort() ListBox1.DataSource = CType(ViewState(‘AList’), ArrayList) ListBox1.DataBind() End Sub ’btnAsc_Click Private Sub btnDesc_Click(sender As Object, e As System.EventArgs) CType(ViewState(‘AList’), ArrayList).Sort() CType(ViewState(‘AList’), ArrayList).Reverse() ListBox1.DataSource = CType(ViewState(‘AList’), ArrayList) ListBox1.DataBind() End Sub ’btnDesc_Click C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here ArrayList arrlist = new ArrayList (); arrlist.Add (‘Tips’); arrlist.Add (‘Tricks’); arrlist.Add (‘Code’); arrlist.Add (‘Samples’); ListBox1.DataSource =arrlist ; ListBox1.DataBind (); ViewState[‘AList’] = arrlist ; } private void btnAsc_Click(object sender, System.EventArgs e) { ((ArrayList)ViewState[‘AList’]).Sort() ; ListBox1.DataSource =(ArrayList)ViewState[‘AList’] ; ListBox1.DataBind (); } private void btnDesc_Click(object sender, System.EventArgs e) { ((ArrayList)ViewState[‘AList’]).Sort() ; ((ArrayList)ViewState[‘AList’]).Reverse (); ListBox1.DataSource =(ArrayList)ViewState[‘AList’] ; ListBox1.DataBind (); }
I get the error message ‘DataGrid with id ‘DataGrid1′ could not automatically generate any columns from the selected data source’ when I bind a HashTable to the DataGrid
Set the AutoGenerateColumns property of the DataGrid to False.Sample code below VB.NET <asp:DataGrid AutoGenerateColumns=False id=’DataGrid1′ runat=’server’> <Columns > <asp:TemplateColumn HeaderText=’HashTable’> <ItemTemplate> <%# Container.DataItem.Key %> <br> <%# Container.DataItem.Value %> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> ’In Page_Load Dim ht As New Hashtable() ht.Add(’emp1′, ‘A’) ht.Add(’emp2′, ‘B’) ht.Add(’emp3′, ‘C’) DataGrid1.DataSource = ht DataGrid1.DataBind() C# <asp:DataGrid AutoGenerateColumns=False id=’DataGrid1′ runat=’server’> <Columns > <asp:TemplateColumn HeaderText=’HashTable’> <ItemTemplate> <%# ((DictionaryEntry)Container.DataItem).Key %><br> <%# ((DictionaryEntry)Container.DataItem).Value %> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> //In Page_Load Hashtable ht = new Hashtable(); ht.Add (’emp1′, ‘A’); ht.Add (’emp2′, ‘B’); ht.Add (’emp3′, ‘C’); DataGrid1.DataSource = ht; DataGrid1.DataBind();
Is it possible to cache a page by Browser Version and/or some params
Yes. In your page: <%@ OutputCache Duration=’60’ VaryByParams=’abc;xyz’ VaryByCustom=’browsermajorversion’ %> In your global.asax file: VB.NET Public Overrides Function GetVaryByCustomString(context As HttpContext, custom As String) As String If custom.ToLower() = ‘browsermajorversion’ Then Dim browser As HttpBrowserCapabilities = context.Request.Browser Return browser.Browser + ‘ ‘ + browser.MajorVersion Else Return MyBase.GetVaryByCustomString(context, custom) End If End Function ’GetVaryByCustomString C# public override string GetVaryByCustomString(HttpContext context, string custom) { if (custom.ToLower() == ‘browsermajorversion’) { HttpBrowserCapabilities browser = context.Request.Browser; return browser.Browser + ‘ ‘ + browser.MajorVersion; } else { return base.GetVaryByCustomString(context, custom); } }
I want to Cache based on HTTP header .How can I do that
<%@OutputCache … VaryByHeader=’UserAgent’ %> or <%@ OutputCache … VaryByHeader=’Accept-Language’ %>
How to prevent client Cache? I want every client request get sent to the server even if it’s behind a proxy server and for any browser setting.
You can use tag <%@ OutputCache Duration=’0′ Location=’None’ VaryByParam=’none’ %> or VB.NET Response.Cache.SetCacheability(HttpCacheability.NoCache) C# Response.Cache.SetCacheability(HttpCacheability.NoCache);