0

In the project I am working in there is webpage which retrieve data from the database. So I have used DataGrid show my data.
But sometimes I wanted to add more columns to the DataGrid.That means I want to add some columns with data dynamically.
However I have new columns addition to the DataGrid and here is my code.

DataGridColumn myCol = new BoundColumn();
myCol.HeaderText = "Test";
myCol.Visible = true;
grdHeiskort.Columns.Add(myCol);  

In here "grdHeiskort" is DataGrid ID.

Now I want to add the data to this column named="test".That data is gain from the database.Suppose I am retrieving dataset from DB and I want to add the data in 1st column in dataset to my "test" column.So how can I do it.

1 Answer 1

1

If you use a BoundColumn you can set the name of the DataField to whatever the name of the field you want it to be from your dataset:

BoundColumn myCol = new BoundColumn();
myCol.HeaderText = "Test";
myCol.Visible = true;
myCol.DataField = "NameOfYourDataColumn";
grdHeiskort.Columns.Add(myCol); 
Sign up to request clarification or add additional context in comments.

1 Comment

Ok.Thank you.Can you tell me how to add Text Field to this column?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.