Posts

Showing posts from May, 2012

How to get Hidden Column Value in GridView

1. First Way - Use DataKeyNames Property of GridView (a) DataKeyNames is used to specify Primary key coulmn(s) of the data source that is bound to the GridView. When DataKeyNames property of GridView is set then values of specified columns are stored in DataKeys collection that is available at runtime.  <asp:GridView ID="dtgOutwardSpare" runat="server" AutoGenerateColumns="False" AutoGenerateSelectButton="True" CellPadding="4" DataKeyNames="AssetID,OutwardTypeID" OnSelectedIndexChanged="dtgOutwardSpare_SelectedIndexChanged" Width="890px" ConvertEmptyStringToNull="true" HtmlEncode="false" HtmlEncodeFormatString="false">  <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="AssetID" HeaderText="AssetID" Visible=...

Chart Error executing child request for ChartImg.axd

The chart would work on one page but not on the next. Turns out if the chart is initialized for the first time in a POST (i.e. a postback) the error is thrown because the handler is configured incorrectly. To fix the issue modify the httpHandler configuration that user LaptopHeaven referred to in this topic by adding the POST verb: In handlers of web.config add the following code: <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />

Export ASP.NET GridView to Excel

In  the  button click event handler  code : protected void btnExcel_Click(object sender, EventArgs e)         {             Response.Clear();             Response.AddHeader("content-disposition", "attachment; filename=Product.doc");             Response.Charset = "";             Response.ContentType = "application/vnd.doc";             StringWriter stringWriter = new StringWriter();             HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);             GridView1.RenderControl(htmlWriter);             Response.Write(stringWriter.ToString());             Response.End();         } But you can use similar code to export to other form...

Data Dictionary in c#

1)How to declare data Dictionary:   Dictionary<key, value> mydictionary = new Dictionary<key, value>(); -> Dictionary can be of any data type combination. ex: int, float,string ->First item in the dictionary will be a key and second item will be a value 2)How to add value to dictionary: mydictionary .Add(key, value); 3)How  to retrieve values and keys from the dictionary: foreach (KeyValuePair<key, value> item in  mydictionary ) {                     string key = item.Key;                     string val = item.Value;                     string outputfile = outputfile + key+"\n"+val;  } 4)How to search an item in dictionary for a value: mydictionary .ContainsValue(value); for a key: mydictionary .ContainsKey( key ); 5)To clear value  from the dictionary myd...