Monday, March 31, 2008

Bound custom data to the Column of the GridView

Today I learned how to attach custom value to the column of the GridView control in ASP.NET page. What I did is as follows

First I click on Edit Templates of the GridView and inside ItemTemplate I dragged one Hyperlink control. For that Hyperlink's NavigateUrl and Text I used databindings.

Later I added new column to the GridView and selected TemplateField. Now the template field column in the GridView shows the Hyperlink whose URL and Text are bound to the custom date.

Unique Identifier Generator in .NET

The following code generates the Unique Identifier in string format..

Wednesday, March 26, 2008

Get Columns Names of the MS SQL Table

Following MS SQL query gives the list of column names of the table_Name

select from sysobjects obj inner join syscolumns col on = where = 'table_Name'

Wednesday, March 19, 2008

RequiredFieldValidator and Button Click Event

If you use RequiredFieldValidator control on your ASP.NET page, every button click will perform validation. If you have rest buttons on your page on whose click you dont want validation, then set CausesValidation property of button to false

Thursday, March 13, 2008

Passing values between ASP.NET pages

Today I learned how to pass values between two pages in ASP.NET. Lets say you have Page1.aspx and Page2.aspx and want to pass values from Page1.aspx to Page2.aspx. You can put link button control on Page1.aspx and on its click event you can write this code

string mydata = "88";
Response.Redirect("Page2.aspx?value=" + mydata);

The above code will open Page2.aspx and now in order to get the value, you can write code on PageLoad event or any other method in code-behind file of Page2.aspx as follows

string mydata = Request.QueryString["value"];

Tuesday, March 11, 2008

Substring of DataList field

The label control which is bind to the field for DataList control of ASP.NET page can be truncated using following syntax


Monday, March 10, 2008

Traverse through SQL Table rows

Here is the code to traverse (iterate) through each row in SQL table...

SET @i = 1

WHILE (@i<= (SELECT count(*) FROM table_name) )
/* Your Code here...*/
SET @i=@i+1

Monday, March 03, 2008

Event Trigger on selection changed in the DropDownList

On ASP.NET page....In order to tigger the event when selection of the DropDownList changes...write code in SelectionIndexChanged event of the DropDownList and dont forget to enable AutoPostBack to True.

Empty TextBox Check using RequiredFieldValidator

In order to check if something is entered into textbox...just drag and drop RequiredFieldValidator user control and set its ControlToValidate property to the desired textbox. And enter the custom error message you like to display...

Now when text is not entered into the desired textbox and page is refreshed using button click event the custom message appears......

Absolute Positioning of User Controls on ASP.NET Page

In Order to position ASP.NET usercontrols in visual control and then Click ( in Visual Studio ) on Layout->Position->Absolute. And then select and move the control on ASP.NET page as you like..

RadioButton GroupName

Simple and Silly but still important...Today I learned how to choose only one radio button among the radio buttons that are placed on the ASP.NET page. Just give the same GroupName (just any text) property of all radio buttons which you either want to select.