Null coalescing: The null coalescing operator “??” uses two question marks. With it you can use a custom value for a null reference variable. It simplifies null tests. C# program that uses null coalescing operator using System; class Program { static string _name; /// <summary> /// Property with custom value when null. /// </summary> static […]
Category: C#
Important Tips To Write Clean Code In C# from Debendra Dash
To develop reusable, reliable, readable, well-structured, and maintainable application, we must follow the coding standard. There are several coding practices in the software industry. None of them are good or bad but the main thing is that whatever approach we follow, we should make sure that everyone should follow the same standard.
Function with variable number of arguments in C#
By using the params keyword, you can specify a method parameter that takes a variable number of arguments. You can send a comma-separated list of arguments of the type specified in the parameter declaration or an array of arguments of the specified type. You also can send no arguments. If you send no arguments, the length of the params list is […]
Devexpress ASPxGridview Column Grouping in Code
The following code shows how to group by two columns (“Country” and “City”).
How to use the second argument of Response.Redirect: True or False
Response.Redirect(URL, false): The client is redirected to a new page and the current page on the server will keep processing ahead. Response.Redirect(“default.aspx”, false); Response.Redirect(URL, true): The client is redirected to a new page, but the processing of the current page is aborted. Response.Redirect(“default.aspx”, true);
How to solve “Response.Redirect cannot be called in a Page callback” for DevExpress Components
DevExpress.Web.ASPxClasses.ASPxWebControl.RedirectOnCallback(“the_redirect_page.aspx”);
How to use and get HiddenField Value in Gridview
You can add HiddenField to the Gridview like that:
Display HTPP Headers in C# & ASP.net
using System; using System.Web.UI; using System.Collections.Specialized; public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { NameValueCollection headers = base.Request.Headers; for (int i = 0; i < headers.Count; i++) { string key = headers.GetKey(i); string value = headers.Get(i); base.Response.Write(key + ” = ” + value + “<br/>”); } } }
Change format of the Day with Leading zero In DateTime
You can use both methods: DateTime.Now.Day.ToString(“00”); DateTime.Now.ToString(“dd”);
Add blank item at top of dropdownlist
drpList.Items.Insert(0, new ListItem(String.Empty, String.Empty)); drpList.SelectedIndex = 0;
Hide GridView Column on server-side
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[index].Visible = false; }
Fire Combobox SelectedIndexChanged with button code-behind
myComboBox_SelectedIndexChanged(myComboBox, new EventArgs()); // or (null, null)




