This is a migrated thread and some comments may be shown as answers.

Need help adding rows programatically via datasource

2 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TIM
Top achievements
Rank 1
TIM asked on 23 Oct 2011, 09:24 PM
Ok, I would like to say I know that you can only add rows programatically by using a datasource and modifying that.

However, i've been googling and searching for a number of hours, and i still cant find a solution.

I am using (VB.Net)


I am trying to figure out how to add rows 'programatically', i have a list that i am compiling on page load...

I would like:

Check Box, image field, and 3 bound fields.

Can anyone give me a quick and simple code snippet to adding values to these rows?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Oct 2011, 04:55 AM
Hello Tim,

I guess yor requirement is to populate RadGrid from code behind. You can populate RadGrid in Page_Load event, but the best approach is you can use NeedDataSource event of RadGrid(if any advanced features like paging,sorting is enabled in RadGrid). In ASPX page you can add corresponding column for each field(eg: GridCheckBox column for CheckBox field and Set its DataField as corrsponding columnName in lIst)Following a sample code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
          onneeddatasource="RadGrid1_NeedDataSource">
          <MasterTableView CommandItemDisplay="Top" DataKeyNames="EmployeeID" EditMode="InPlace">
              <Columns>
                  <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="FirstName">
                  </telerik:GridBoundColumn>
                  <telerik:GridCheckBoxColumn DataField="isapproved">
                  </telerik:GridCheckBoxColumn>
              </Columns>
          </MasterTableView>
       </telerik:RadGrid>

VB.NET:
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
    RadGrid1.DataSource = //populate RadGrid with Your List
End Sub

-Princy.
0
TIM
Top achievements
Rank 1
answered on 24 Oct 2011, 01:40 PM
I appreciate you taking your time to respond, but my problem is being unsure what vb code and the usage of it is to set the values.

So, I guess ideally I would like to see a vb.net (from the .vb file) a example of adding the values.
Tags
Grid
Asked by
TIM
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
TIM
Top achievements
Rank 1
Share this question
or