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

Detail grid - 2 Questions

3 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcia Marino
Top achievements
Rank 1
Marcia Marino asked on 23 Feb 2008, 05:05 AM
I'm using the custom grid, I need to a detail grid to it using Store Procedure, how can I do that using the

protected

void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

{

this.RadGrid1.DataSource = ImagesLibraryDB.GetLibraries(localeId, prefLanguage, memberId, portalId);

this.tableViewOrders.DataSource = ImagesLibraryDB.GetImageForLibrary(portalId, memberId, Convert.ToInt32("LibraryID"].ToString()));

}


Also I'm using

RadGrid1.MasterTableView.EditFormSettings.UserControlName =

"~/BackOffice/ImagesLibrary/Libraries.ascx";

for edit or create a new item, how can I make the update botton invisible if I'm adding a new record.


private void DefineGridStructure()

{

 

RadGrid1.ID =

"RadGrid1";

RadGrid1.Width =

Unit.Percentage(98);

RadGrid1.AllowPaging =

true;

RadGrid1.AllowSorting =

true;

RadGrid1.PagerStyle.Mode =

GridPagerMode.NumericPages;

RadGrid1.AutoGenerateColumns =

false;

//RadGrid1.EnableAJAX = true;

RadGrid1.GridLines =

GridLines.None;

RadGrid1.ShowStatusBar =

true;

RadGrid1.AllowAutomaticDeletes =

true;

RadGrid1.AllowAutomaticInserts =

false;

RadGrid1.AllowAutomaticUpdates =

true;

 

RadGrid1.MasterTableView.DataKeyNames =

new string[] { "LibraryID" };

RadGrid1.MasterTableView.AutoGenerateColumns =

false;

RadGrid1.PageIndexChanged +=

new Telerik.Web.UI.GridPageChangedEventHandler(this.RadGrid1_PageIndexChanged);

RadGrid1.NeedDataSource +=

new Telerik.Web.UI.GridNeedDataSourceEventHandler(this.RadGrid1_NeedDataSource);

RadGrid1.ItemDataBound +=

new Telerik.Web.UI.GridItemEventHandler(this.RadGrid1_ItemDataBound);

RadGrid1.ItemCommand +=

new GridCommandEventHandler(RadGrid1_ItemCommand);

GridBoundColumn boundColumn;

boundColumn =

new GridBoundColumn();

boundColumn.DataField =

"Title";

boundColumn.HeaderText = title;

boundColumn.SortExpression =

"Title";

boundColumn.UniqueName =

"Title";

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn =

new GridBoundColumn();

boundColumn.DataField =

"Description";

boundColumn.HeaderText = description;

boundColumn.SortExpression =

"Description";

boundColumn.UniqueName =

"Description";

boundColumn.MaxLength = 500;

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn =

new GridBoundColumn();

boundColumn.DataField =

"CreatedDt";

boundColumn.HeaderText = createddt;

boundColumn.SortExpression =

"CreatedDt";

boundColumn.UniqueName =

"CreatedDt";

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn =

new GridBoundColumn();

boundColumn.DataField =

"UpdatedDt";

boundColumn.HeaderText = updateddt;

boundColumn.SortExpression =

"UpdatedDt";

boundColumn.UniqueName =

"UpdatedDt";

RadGrid1.MasterTableView.Columns.Add(boundColumn);

GridButtonColumn buttoncolumn;

buttoncolumn =

new GridButtonColumn();

buttoncolumn.HeaderText = restore;

buttoncolumn.Text = restore;

buttoncolumn.ConfirmText = strconfirmdelete;

buttoncolumn.ButtonType =

GridButtonColumnType.ImageButton;

buttoncolumn.ImageUrl =

"~/Images/grid/refresh.gif";

buttoncolumn.CommandName =

"Restore";

RadGrid1.MasterTableView.Columns.Add(buttoncolumn);

buttoncolumn =

new GridButtonColumn();

buttoncolumn.HeaderText = delete;

buttoncolumn.Text = delete;

buttoncolumn.ConfirmText = strconfirmdelete;

buttoncolumn.ButtonType =

GridButtonColumnType.ImageButton;

buttoncolumn.ImageUrl =

"~/Images/grid/delete.gif";

buttoncolumn.CommandName =

"Delete";

RadGrid1.MasterTableView.Columns.Add(buttoncolumn);

tableViewOrders.DataKeyNames =

new string[] { "ImageID" };

GridRelationFields relationFields = new GridRelationFields();

relationFields.MasterKeyField =

"LibraryID";

relationFields.DetailKeyField =

"LibraryID";

tableViewOrders.ParentTableRelation.Add(relationFields);

RadGrid1.MasterTableView.DetailTables.Add(tableViewOrders);

string veditColumnName = "GroupID";

string vcArg = "";

int vcount = -1;

string vtype = "Image";

GridTemplateColumn veditColumn = new GridTemplateColumn();

veditColumn.ItemTemplate =

new editTemplate(veditColumnName, vcArg, vcount, vtype);

RadGrid1.MasterTableView.Columns.Add(veditColumn);

boundColumn =

new GridBoundColumn();

boundColumn.DataField =

"Title";

boundColumn.HeaderText = title;

boundColumn.SortExpression =

"Title";

boundColumn.UniqueName =

"Title";

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn =

new GridBoundColumn();

boundColumn.DataField =

"Description";

boundColumn.HeaderText = description;

boundColumn.SortExpression =

"Description";

boundColumn.UniqueName =

"Description";

boundColumn.MaxLength = 500;

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn =

new GridBoundColumn();

boundColumn.DataField =

"CreatedDt";

boundColumn.HeaderText = createddt;

boundColumn.SortExpression =

"CreatedDt";

boundColumn.UniqueName =

"CreatedDt";

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn =

new GridBoundColumn();

boundColumn.DataField =

"UpdatedDt";

boundColumn.HeaderText = updateddt;

boundColumn.SortExpression =

"UpdatedDt";

boundColumn.UniqueName =

"UpdatedDt";

RadGrid1.MasterTableView.Columns.Add(boundColumn);

//Add the RadGrid instance to the controls

this.PlaceHolder1.Controls.Add(RadGrid1);

}

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 26 Feb 2008, 07:24 AM
Hello Marcia,

To see more information on using the control with stored procedures, please refer to the following code library. Additionally, RadGrid does not limit you to using design time datasource object, you can also use the NeedDataSource event handler, to pass a valid datasource to the control. For example, let us assume that you have created the following stored procedure:

USE AdventureWorks;  
GO  
CREATE PROCEDURE testProc1  
AS  
SELECT OrderQty, LineTotal  
FROM Sales.SalesOrderDetail  
   WHERE ProductID = '744';  
 
 

Then, in the NeedDataSource event handler, you can use code like this:

.cs
  protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
    {  
        System.Data.SqlClient.SqlConnection objConn = new System.Data.SqlClient.SqlConnection();  
        objConn.ConnectionString = "server=.; database=DataBaseName; uid=sa;pwd=test;";  
        objConn.Open();  
        System.Data.SqlClient.SqlCommand objCmd = new System.Data.SqlClient.SqlCommand("testProc1", objConn);  
        objCmd.CommandType = System.Data.CommandType.StoredProcedure;  
        RadGrid1.DataSource = objCmd.ExecuteReader();        
    } 

In essense, it is up to you how you connect to the server to extract the data. You only need to pass a valid datasource to the control, in the proper handler .

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Marcia Marino
Top achievements
Rank 1
answered on 28 Feb 2008, 02:37 AM
Sorry maybe you didn't understand my question

the grid is filled with

this.RadGrid1.DataSource = ImagesLibraryDB.GetLibraries(localeId, prefLanguage, memberId, portalId);

witch is fine
now I need to fill the detail grid based on the libraryid from the main grid

this.tableViewOrders.DataSource = ImagesLibraryDB.GetImageForLibrary(portalId, memberId, Convert.ToInt32("LibraryID"].ToString()));


the question is how do I get the LibraryID from the frist statement

the question is how do I get the LibraryID from the frist statement
0
Yavor
Telerik team
answered on 04 Mar 2008, 11:32 AM
Hi Marcia,

You can use the DetailTableDatabind handler, to pass a datasource for the detail level. One implementation is demonstrated in the following example. Is shows how to get a reference to the parent item, which is already populated with data, and hence gives you access to the parent key value.

Regards,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Marcia Marino
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Marcia Marino
Top achievements
Rank 1
Share this question
or