Skip to main content

Posts

Showing posts from April, 2010

How to generate the dynamic rad menu !

1.Add a .dll in your project(RadMenu.Net2.dll) 2.On the .aspx page .add the following code padding-top: 11px;" ValidationGroup="AdminMenu"> On the Page Load add the menthod protected void BindMenu() { DataSet ds = new DataSet(); SqlConnection con = new SqlConnection("server=.;database=a;uid=b;password=b;"); con.Open(); SqlDataAdapter adpmenu = new SqlDataAdapter("Select Menu_Id+10000 as IdMenu,Menu_name as name ,null as Parent from tbl_Menu union Select Sub_MenuId,Sub_MenuName, Menu_Id+10000 as Parent from tbl_SubMenu order by Parent", con); adpmenu.Fill(ds); con.Close(); DataTable dt1 = ds.Tables[0]; Rad_top_menu.DataTextField = "name"; // Rad_top_menu.DataNavigateUrlField = "url"; Rad_top_menu.DataFieldParentID = "parent"; Rad_top_menu.DataFieldID = "idmenu"; ...

How can you implement tree structure with checkboxes!

Drag and Drop a tree view contols from the toolbox on the .aspx page LeafNodeStyle-NodeSpacing="10px" LeafNodeStyle-HorizontalPadding="25px" ShowCheckBoxes="All" runat="server" > Add javascripts functions to check and uncheck all the checkboxes from tree hirerichy On the coding Page 1.Add the attribute on the Page_load Events protected void Page_Load(object sender, EventArgs e) { BindData(); TreeView1.Attributes.Add("onclick", "OnCheckBoxCheckChanged(event)"); } 2.Set the Parent and child relationship between the nodes protected void BindData() { DataSet ds=new DataSet(); SqlConnection con=new SqlConnection("server=.;database=ABC;uid=dd;password=dd;"); con.Open(); SqlDataAdapter adpmenu=new SqlDataAdapter("Select * from tbl_Menu",con); SqlDataAdapter adpsubmenu=new SqlDataAdapter(...

Minimum and Maximum Character Validation on Input.

During development in .NET you came across a situation when we require min Minimum and maximum length checks on text boxes. Microsoft provided a very easy way to apply maximum length check. You just need to set MaxLength property. But to apply Min Length there is no such property. This check can be done using CustomValidator in the following way. Write a javascript function which validates the input, Place TextBox and CustomValidator on page and set ClientValidationFunction property to the Function wriiten in javascript to validate input. function validateLength ( src, args ) { if (val.length >= 10) { args.IsValid = flag; } else { args.IsValid = false; } }

how to control "page refresh" in asp.net page

Many of us face a problem in asp.net pages that is last event fired when user refresh the page.for example if user is adding a record and after adding the record  he hits "F5" to refresh the page then the last add event will fire again and insert duplicate record. elow is an example of how to handle this. -----------------------------------------------------------------------------------   protected void Page_Load(object sender, EventArgs e)    {         if (!IsPostBack)         {             Session["value"] = Server.UrlEncode(System.DateTime.Now.ToString());         }     }  protected void Page_PreRender(object sender, EventArgs e)     {         ViewState["value"] = Session["value"];  protected void btnSubmit_Click(object sender, EventArgs e)     {         if (Session["value"].ToString() == ViewState["value"].ToString())         {             lblMsg.Text = "Button clicked";             Session["value"] ...

code to get virtual path of current application directory c#

public static string WebsiteRootUrl        {            get            {                string strAppPath;                if (HttpContext.Current.Request.ApplicationPath != "/")                    strAppPath = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;                else                    strAppPath = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);                return strAppPath + "/";            }        }

Image Randomizer in Asp.Net!

DirectoryInfo di = new DirectoryInfo(HttpContext.Current.Server.MapPath("Images")); FileInfo[] rgFiles = di.GetFiles(); if (rgFiles.Length > 0) { img1.ImageUrl ="http://localhost:51794/WebSite/Images/"+ rgFiles.GetValue(new Random().Next(0, rgFiles.Length - 1)); }

How to download file in c#

string str = "E:\\abc.txt"; FileInfo fileInfo = new FileInfo(str); if (fileInfo.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.Flush(); Response.WriteFile(fileInfo.FullName); }

Change the Color of a gridview's row based on some condition!

In the RowDataBound Event of gridview protected void grdviewtopmanager_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Int32 ID = Convert.ToInt32(((HtmlInputHidden)e.Row.FindControl("UIDHiddenCat")).Value); string MID=Convert.ToString(((HtmlInputHidden)e.Row.FindControl(Constants.UIDHidden)).Value); Label lblcmny= (Label)e.Row.FindControl("lblcompany"); HtmlAnchor htmobj= (HtmlAnchor)e.Row.FindControl(Constants.hrefmcompany); htmobj.HRef = "TopManager_PropertyDetail.aspx?startdate=" + startdate + "&enddate=" + enddate + "&MID=" + MID; if (ID == 1) { //lblcmny.ForeColor = System.Drawing.Color.Red; e.Row.BackColor= System.Drawing.Color.Red; lblcmny.Font.Bold = true; } ...