Showing posts with label visual c#. Show all posts
Showing posts with label visual c#. Show all posts

Tuesday, May 18, 2010

C#.Net: Dynamic Gridview Header from Resource

Here is something helpful for you guys. I modified the solution that I found on the web since what I found used a different method of setting the column headers. Here is the scenario:

You have a Gridview which is populated dynamically by databinding it to a dataset and you have a resource file (we will call it fielders) which consists of the list of field names used in the dataset. The question is how you can related them to each other? Here are the steps:

Select your Gridview and look for the event RowDataBound and double click on it.
Type the following code.

if (e.Row.RowType == DataControlRowType.Header)
{
     foreach (Tablecell tc in e.Row.Cells)
     {
          tc.Text = Resources.fielders.ResourceManager.GetString(tc.Text);     }

}

Hope this helped you guys. Remeber to put this code in your Gridview's RowDataBound.

Monday, May 10, 2010

Visual C#.Net: Optional Parameters

I've been developing desktop applications in VB6 before and been using the OPTIONAL class where a parameter is not totally required in your function. However, upon developing applications in Visual C#.Net, I didn't find that option. After googling around I found out that you can also do optional parameters on your function. Here is how you can do it.

in the declarations, add this:

using System.Runtime.InteropServices;

After doing it, you may be able to use Optional class like how I used it below;

public string WhatsUp (string UrMessage, [Optional] string Name)
{
     if (Name != "")
     {
          return UrMessage + ", " + Name;
     }
     else
     {
          return UrMessage;
     }
}


Enjoy developing applications people.