z
 
:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:        
  passwords:  

Asp.Net FAQs

Asp.NET 2.0 Qs

Knowledgebase

Interview Questions Asp.net [1]
Interview Questions Asp.net[2]
Interview Questions Asp.net[3]
Interview Questions Asp.Net 2.0[New]
Creating Virtual Directories in IIS using .NET
ASP.NET Web Server Performance Tuning: A Few Real-World Techniques
.NET Development[Forum]
Asp.Net Discussion[Forum]
Code Samples

Articles

Tools

 

Resources

Finding Correct Content Managemet System
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Workflow Managemet Systems
Workflow management is a crucial component in organizing a variety of business processes so that they benefit the business as a whole and increase profitability...

Using the Power of Content Management Systems
With page editors that resemble a word processor program, adding content with a CMS interface is simple and fun. Most CMS software also allows you to change the location of your content pages and links easily, while the back end processes takes care of updating the links throughout your site...

Content Management Systems (CMS): What They Are And Why We Love Them
In the past, individuals who took interest in having and operating their own websites were burdened with the task of learning HTML, DHTML, and other web-based technologies such as JavaScript and CSS. The only alternative to this was, unfortunately, to pocket the expenses and costs required to pay a web developer to build and maintain it for them...

Outsourcing
Post your project for outsourcing and get bids from qualified programmers, designers, interpreters, copywriters.


 

Code Walkthroughs

Datagrid Formatting the Data
We are able to format the content of the datagrid cell by one of two simple methods, dependant upon whether the column is a bound column or whether it is a template column. In our example we shall format the column to have to digits after the decimal point , followed by a...

Datagrid Highlight a Row With Click Through
It is relatively easy to add alternating colours to the rows in your datagrid. However, when we move the mouse over the rows we may want to highlight this row, and possibly to add the option of a click through based on the row selected...

Add a Delete Button to a Datagrid
To add a delete button to a datagrid follows a similar process to adding an edit button. In the datagrid header...

Add an Edit Button to a Datagrid
The datagrid has a predefined editColumn for handling the editing of a datagrid. Adding this simple column definition to a datagrid adds a powerful feature. When a row is not in edit mode the column item shows the word...

Making a Datagrid Row Editable
Two of the most popular methods of editing a datagrid in asp.net are to either select the row and take the user off to a different presentation of the data, or to change the formatting of the row presented in the database with appropriate edit text boxes, checkboxes and...

Adding Tooltips to Datagrid Rows
Adding tooltips to datagrid rows is easy, assuming that you have already created the code for adding row highlighting. In this article I shall assume that you have already read the article entitled Datagrid Highlight a Row With Click Through...

Binding a Datagrid to an Access Database
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Adding Data to a DropDownList
The aim of this article is to answer the question 'How do I add items to a DropDownList?' Initially as part of the declaration for the DropDownList we can also define a number of items, much in the same way as in classic ASP...

Getting Current Date Time
In classic ASP we had now() which would return the current date and time. For asp.net this no longer exists. So what should we use...

Test if File Exists
Sometimes, in order to reduce our chance of error, when working with the filesystem in ASP.NET, we need to determine wether a file exists before performing an action on it. The following short piece of code will enable us to test whether a file exists...

Using Javascript with ASP.NET Form Elements
Adding simple pieces of Javascript to an Asp.net page can be acheived by adding to the attributes of the particular imagebutton or linkbutton. if its normal ASP.Net Button then you can...

Regular Expressions
In the table below we list the characters used in .Net regular expressions, together with their meaning, But first...

Authentication in Asp.net
Forms authentication in ASP.Net is far more easier and safe than Asp 3. It is possible to place a web.config file in any directory of a web site.Therefore, we are able to make most of a web site public, whilst providing authentication on, say, one directory...

Discussion Forums

General ASP.NET

.Net Programming

cSharp Home

Sql Server Home

Javascript / Client Side Development

IT Jobs

Ajax Programming

Ruby on Rails Development

Perl Programming

C Programming Language

C++ Programming

Python Programming Language

Laptop Suggestions?

TCL Scripting

Fortran Programming

Scheme Programming

Add an Edit Button to a Datagrid 

The datagrid has a predefined editColumn for handling the editing of a datagrid. Adding this simple column definition to a datagrid adds a powerful feature. When a row is not in edit mode the column item shows the word (or button dependant upon link type) Edit.  Clicking on this link will change the row into edit mode.  Convertng items into text boxes and changing the link edit to the two links update and delete.

To add an edit Button to a datagrid we need to add a few blocks of code.

  1. In the datagrid header
  2. In the column definitions of the datagrid add another column
  3. In the code behind add an event handler for the edit button
  4. In the code behind add an event handler for the update button
  5. In the code behind add an event handler for the cancel button
  6. Ensure that the postback is handled correctly

 

Datagrid header

OnEditCommand="doPurchasingEdit"
OnUpdateCommand="doPurchasingUpdate"
OnDeleteCommand="doPurchasingDelete"

Column definitions of the datagrid

<asp:editcommandcolumn buttontype="LinkButton" UpdateText="Update" cancelText=Cancel" EditText="Edit"></ASP:EditCommandColumn>

Code behind edit button event handler

Sub myDataGridEdit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
    myDataGrid
.EditItemIndex = e.Item.ItemIndex
    BindDataGrid()
End Sub 'myDataGridEdit

Code behind update button  event handler

Sub myDataGridCancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
    myDataGrid.EditItemIndex = -1
    BindPataGrid()
End Sub 'dmyDataGridCancel

Code behind cancel button  event handler

Sub myDataGridUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
    If e.CommandName = "Update"
Then
       
Dim id As Integer
= e.Item.Cells(0).Text
        Dim name As String = CType
(e.Item.FindControl("Name"), TextBox).Text
        Dim description As String = CType
(e.Item.FindControl("Description"), TextBox).Text
        Dim price As String = CType
(e.Item.FindControl("price"), TextBox).Text
        'Create the appropriate SQL statement
       
Dim myConnection As
SqlConnection
        Dim myCommand As
SqlCommand
        Dim myDataReader As
SqlDataReader
        Dim strSQL As
String
        strSQL = "UPDATE table SET name = '" & name & "', description = '" & description & "', price = " &     price & " WHERE id = " & id
        myConnection = New
SqlConnection(ConfigurationSettings.AppSettings("MyDSN"))
        myCommand =
New
SqlCommand(strSQL, myConnection)
        Dim myDataSet As
DataSet
        myConnection.Open()
        myDataReader = myCommand.ExecuteReader()
        myConnection.Close()
        'Rebind the DataGrid
        myDataGrid.EditItemIndex = -1
        BindmyDataGrid()
        myDataGrid.Visible =
True
    End
If
End Sub

Postback

If IsPostBack = True Then
Else
    BindDataGrid()
End if


::  Home :: Services ::  Prices ::  Request Quote
Copyright 2007, Megasolutions Ltd