Using Response object in a Class

If you try this, straight away, you will probably receive an error message, telling you the Response object is not available in this context.

So, in order to get rid of the error message, Import System.Web, and then, change :
Response.(whatever)
to
HttpContext.Current.Response.(whatever)

Get Row Index with Gridview Select Button

When you autoGenerate a Select button with a Gridview, to find the RowIndex for that particular row, you can use the SelectedIndexChanged Event. Inside that event, try something like this (with a label called ‘Label1′:

Dim row As GridViewRow = MyGridView.SelectedRow Dim intRow as Integer=Row.RowIndex label1.text=intRow.ToString

Add 'Select' feature to existing Button/Imagebutton in TemplateField

If you already have any kind of button, whether it be a plain button, LinkButton, or Imagebutton, in a TemplateField, within a GridView, you can add ‘Select’ features to it, just as if you had added a ‘Select’ column.

All you need to do is add ‘Select’ to the CommandName property. Then, anything you could do with the Select CommandField, you can do with your own TemplateField.

Select DDL Item After Declarative Databinding

The new declarative controls of V2.0 are really great. However, there are some times, when it may not seem so. Let’s say you have a DropDownList which is bound by a DataSource control. Also, you have other pages hitting this page, with querystrings, and based on the item in the querystring, you’d like the to select that item.

In v1.0, you’d just code it, and select it after the code, or in the Pre-render event.

Now, all you do is put your code logic in the DataBound event of the Dropdownlist (DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(Request.Querystring(“YourQuerystring”)))

Reading objects from a table or div.

Our eg. reads all dropdown lists from a table (id=tblTest)
(1) First read the object (table in our case) from which you need other objects.

var varTblTest = document.getElementById(‘tblTest’) ;

(2) Next you can find all the dropdown in the tblTest by the method, “getElementsByTagName”. The dropdown list renders as tag, “select”.

var varDdlsFromTable = varTblTest.getElementsByTagName(‘select’) ;

(3) Now varDdlsFromTable will have all the dropdownlists from the table in the form of array. You can loop through the array now to get individual object.

for(var i = 0 ; i < varDdlsFromTable.length ; i++)
{
alert(varDdlsFromTable[i].value) ; //gives the value of the ddl
alert(varDdlsFromTable[i][varDdlsFromTable[0].selectedIndex].text ; //gives the visible value of the ddl
}

Note: Instead of table it can be anything like, div, tr etc.
Write to me for any js related issues. Happy Coding

Two Databound Fields in Gridview column

Boundfields are great in the Gridview, but they do have their limitations. One is that it only has room for one bound field. So, what do you do when you want two or data fields (like First and Last names) returned to the same column?

Turn the BoundField into a TemplateField, with a label in it:

<asp:TemplateField>
     <ItemTemplate>
         <asp:Label ID="lblname" runat="server" Text='<%# Eval("Lname") +", "+ Eval("Fname") %>'></asp:Label>
     </ItemTemplate>
</asp:TemplateField>