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

Data Binding in Grid

3 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Susi
Top achievements
Rank 1
Susi asked on 02 Jul 2012, 11:40 AM
Hi All,
 I am developing product using asp.net using c sharp..i have two methods are called selectRoles and SelectRoleFeature and i have to bind those two methods in single RadGrid. Here display selectRoles are parent and SelectRoleFeatures are child in Grid through expand and collapse.which type of grid do this. How to implement this scenario..

Thanks in Advance..!

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Jul 2012, 12:50 PM
Hello,

Please check below links.
Grid / Programmatic Binding :
By using above demo you can assign selectRoles in  NeedDataSource event.
you can assign SelectRoleFeature  in  DetailTableDataBind event (You can use DataKey to show particular role's feature).


Thanks,
Jayesh Goyani
0
Susi
Top achievements
Rank 1
answered on 03 Jul 2012, 07:54 AM
Hi jayesh,

Thanks for your reply..my grid is binding...Here i need assign and un-assign RoleFeature to Particular Roles by checkbox in Grid..how to make checkbox with grid and My Grid displaying not perfectly my code is below..

my aspx.cs code is,
public partial class RoleAndRoleFeature : System.Web.UI.Page
   {
       ApplicationProcess a = new ApplicationProcess();
       protected void Page_Load(object sender, EventArgs e)
       {
 
       }
 
       protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
       {
           RadGrid1.DataSource = a.GetRoles();
           //RadGrid1.DataBind();
       }
 
       protected void RadGrid1_DetailTableDataBind(object sender, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
       {
           RadGrid1.DataSource = a.GetRoleFeatures(1);
          // RadGrid1.DataBind();
       }
   }


my aspx page code is,
       <telerik:RadGrid ID="RadGrid1" runat="server" ShowStatusBar="true"
        AutoGenerateColumns="false"
        ondetailtabledatabind="RadGrid1_DetailTableDataBind" onneeddatasource="RadGrid1_NeedDataSource"
       
       >
    <MasterTableView DataKeyNames="ID" Width="100%" AllowMultiColumnSorting="true"
        HierarchyDefaultExpanded="false">
        <SelfHierarchySettings ParentKeyName="ParentRoleFeatureId" KeyName="ID" />
        <DetailTables>
            <telerik:GridTableView DataKeyNames="ID" DataMember="RoleFeatures" Width="100%"
                Caption="RoleFeature">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="ID" MasterKeyField="ID" />
                </ParentTableRelation>
                <Columns>                                           
                                    <telerik:GridBoundColumn SortExpression="Name" HeaderText="RoleFeature"
                        HeaderButtonType="TextButton" DataField="Name">
                    </telerik:GridBoundColumn>
                </Columns>
            </telerik:GridTableView>
           
        </DetailTables>
        <Columns>
            <telerik:GridBoundColumn SortExpression="ID" HeaderText="ID" HeaderButtonType="TextButton"
                DataField="ID">
            </telerik:GridBoundColumn>
          
            <telerik:GridBoundColumn SortExpression="Name" HeaderText="RoleName" HeaderButtonType="TextButton"
                DataField="Name">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn SortExpression="Description" HeaderText="Description"
                HeaderButtonType="TextButton" DataField="Description">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings AllowExpandCollapse="true">
    </ClientSettings>
</telerik:RadGrid>




0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Jul 2012, 01:34 PM
Hello Susi,

Please do following changes in above code.

Please modify below code
protected void RadGrid1_DetailTableDataBind(object sender, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
   {
 
        GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
string RoleID = dataItem.GetDataKeyValue("ID").ToString();
      e.DetailTableView.DataSource = a.GetRoleFeatures(RoleID);
   }

Remove below code.
<SelfHierarchySettings ParentKeyName="ParentRoleFeatureId" KeyName="ID" />


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Susi
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Susi
Top achievements
Rank 1
Share this question
or