Thijs
Thijs

Reputation: 3055

Gridview update a column using another column

I have a gridview bound with a database. I would like to add an extra column which has a linkbutton. The intention is that when clicked on the linkbutton, the user could toggle the value of a column which is bounded with the database.

I don't have any good ideas how to get started on this. Any help would be greatly appreciated!

Regards, Thijs

Upvotes: 0

Views: 228

Answers (2)

huMpty duMpty
huMpty duMpty

Reputation: 14470

If I understand you question,

Make you gridview template fields. you can find more about Using TemplateFields in the GridView Control

Place the linkbutton with a commandname. See ButtonField.CommandName Property

In here do the same for the field you need to access. You will be able to access the values and change as you need.

Hope this helps

Upvotes: 1

Azhar Khorasany
Azhar Khorasany

Reputation: 2709

Right the way I would approach this is declare a class called GridRecord or something that represents a grid row.

class GridRecord
{
}

then in the class define all properties that will be the columns of your grid including the link column.

class GridRecord
{
    private Image m_Link = [some image];
    public GridRecord(){}

    public Image Link
    {
        get { return m_Link; }
    }
}

then in your grid code:

IList<GridRecord> records = new List<GridRecords>();
//Fill records object as you like.
Grid1.DataSource = records;

Then handle the RowCellClick or similar event and check if the clicked cell is of property type Link and use it.

Upvotes: 0

Related Questions