Is there any code sample that can help me to write the web part?
Thanks
7 Answers, 1 is accepted
To see more information along the lines of the requested functionality, please refer to the following post. I hope it gets you started properly.
Regards,
Yavor
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thanks for your response. I was able to have the RadGrid working in my webpart. It displays my data as expected.
I have a problem with Edit functionality. The AutoGenerateEditColumn property it set to True. When I click on the edit, I got the following error:
"Multiple controls with the same ID 'AutoGeneratedEditButton' were found. FindControl requires that controls have unique IDs. "
It would be great to help me out with this issue.
Regards,
Sanaz
Is it possible that you have more than one auto-generated edit column in your grid? If so, remove the other auto-generated edit column instances to see whether this eliminates the exception. Alternatively, if you need additional edit column, consider adding a template column with edit button inside its item template (having CommandName="Edit" for it).
Best regards,
Stephen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Hi,
By setting the EnableColumnsViewState to false my previous problem has gone.
Now I have problem inserting new record into the grid. I've attached my code. On the edit form, insert button does not call the insert method "InsertAdminComment" so the new record doesn't insert.
I appreciate your help.
Thanks,
public partial class CommentsWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
private RadGrid gvComments = null;
private ObjectDataSource ods=null;
private ObjectDataSource odsFiscalYear;
private Panel pnlContainer { get; set; }
#region Overrides
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
EnsureChildControls();
}
protected override void CreateChildControls()
{
DefineGridStructure();
base.CreateChildControls();
}
#endregion
# region private method
private void DefineGridStructure()
{
pnlContainer = new Panel();
this.Controls.Add(pnlContainer);
pnlContainer.EnableViewState = false;
//Represents the specified types
Type typeAdminComments = typeof(AdminComments);
Type typePeriods=typeof(Periods);
//Object Data Source
ods = new ObjectDataSource(typeAdminComments.AssemblyQualifiedName.ToString(), "GetAdminCommentsByUserID");
ods.ID = "ods1";
ods.SelectParameters.Add("UserID", "test");
ods.InsertMethod = "InsertAdminComment";
ods.InsertParameters.Add("FiscalYear", "2008");
ods.InsertParameters.Add("Comment", "my first test Heyyyyyyyy");
odsFiscalYear = new ObjectDataSource(typePeriods.AssemblyQualifiedName.ToString(), "GetFiscalYears");
odsFiscalYear.ID = "odsFiscalYear";
//Grid Defininition
gvComments = new RadGrid();
gvComments.ID = "gvComments1";
gvComments.Skin = "Vista";
gvComments.AutoGenerateColumns = false;
gvComments.AllowAutomaticUpdates = true;
gvComments.AllowAutomaticDeletes = true;
gvComments.AllowAutomaticInserts = true;
gvComments.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
//Events
gvComments.ItemInserted += new GridInsertedEventHandler(gvComments_ItemInserted);
gvComments.MasterTableView.EnableColumnsViewState = false;
gvComments.DataSourceID = ods.ID;
pnlContainer.Controls.Add(ods);
pnlContainer.Controls.Add(odsFiscalYear);
pnlContainer.Controls.Add(gvComments);
//Grid Columns
GridDropDownColumn d = new GridDropDownColumn();
d.HeaderText = "Fiscal Year";
d.DataField = "FiscalYear";
d.ListValueField = "ValueField";
d.ListTextField = "TextField";
d.DataSourceID = "odsFiscalYear";
//gvComments.Columns.Add(d);
gvComments.MasterTableView.Columns.Add(d);
GridBoundColumn b = new GridBoundColumn();
b.HeaderText = "Comment";
b.DataField = "Comment";
gvComments.MasterTableView.Columns.Add(b);
GridEditCommandColumn e = new GridEditCommandColumn();
e.HeaderText = "Edit";
e.UniqueName = "EditCol";
gvComments.MasterTableView.Columns.Add(e);
GridButtonColumn del = new GridButtonColumn();
del.HeaderText = "Delete";
del.UniqueName = "DelCol";
del.CommandName = "Delete";
del.Text = "Delete";
del.ConfirmText = "Delete this comment?";
gvComments.MasterTableView.Columns.Add(del);
}
#endregion
#region Events
protected void gvComments_ItemInserted(object source, GridInsertedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
e.KeepInInsertMode = true;
//DisplayMessage("Record cannot be inserted. Reason: " + e.Exception.Message);
}
else
{
//DisplayMessage("Record inserted");
}
}
#endregion
}
ViewState is disabled in your case: pnlContainer.EnableViewState = false;
You need to enable this if you want this event to be executed.
All the best,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Hi – Great - Now the inset method is called and the event is fired.
I want to add another column to my grid that is a boundcolumn “DateUpdated”. The DateUpdated is not a parameter of 'InsertAdminComment' method. When I added the column I got the following error when inserting
"ObjectDataSource 'ods1' could not find a non-generic method 'InsertAdminComment' that has parameters: FiscalYear, Comment, DateUpdated"
How can I fix this? There are going to be more columns in the grid but not in the insert method parameters. Is it necessary that the columns in the grid match with the parameters in the insert/update/delete methods?
Thanks
You can set ReadOnly to true for this column.
Sincerely yours,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
