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

RadGrid update with external button

1 Answer 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
stonger
Top achievements
Rank 1
stonger asked on 08 Jan 2012, 12:58 PM
Please help

I have the following situation:

radgrid with custom template and editmode set to editformtype="template" and editmode="editforms". Also, defined

 

OnUpdateCommand="RadGrid2_UpdateCommand

for the first version and

OnItemCommand="RadGrid1_ItemCommand"

for the second version.

First I put radgrid item in editmode with first button:

RadGrid2.EditIndexes.Add(0);
RadGrid2.Rebind();


On the second button I am trying to bubble grid update from button control that is outside the radgrid like this:
if (commandButton.CommandName.ToLower() == "update")
            {
                foreach (GridEditFormItem item in RadGrid2.MasterTableView.GetItems(GridItemType.EditFormItem))
                {
                   RadGrid2.MasterTableView.PerformUpdate(item, true); // first version
                   item.FireCommandEvent("Update", string.Empty); //second version
                }

The corresponding event handlers bubble but I can`t get values from custom template radtextboxes:

 

<EditFormSettings EditFormType="Template" >
                            <EditColumn UniqueName="EditColumn"></EditColumn>
 <FormTemplate>
                                    <div>
                                        <tr>
                                            <td>
                                                Inicijali
                                            </td>
                                            <td>
                                                <telerik:RadTextBox ID="Inicijali" runat="server" Font-Names="Verdana" Font-Size="Small"
                                                    Text='<%# Bind("Inicijali") %>'>
                                                </telerik:RadTextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Kratica imena
                                            </td>
                                            <td>
                                                <telerik:RadTextBox ID="KraticaImena" runat="server" Font-Names="Verdana" Font-Size="Small"
                                                    Text='<%# Bind("KraticaImena") %>'>
                                                </telerik:RadTextBox>
                                            </td>
                                        </tr>.....</table>

RadGrid definition:

<telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="DetailsViewSQLDataSource"
                        AutoGenerateColumns="false" OnUpdateCommand="RadGrid2_UpdateCommand" OnItemCommand="RadGrid1_ItemCommand"
                        AllowAutomaticUpdates="true">
                        <MasterTableView DataSourceID="DetailsViewSQLDataSource" AutoGenerateColumns="true"
                            DataKeyNames="IdOsobe" ShowHeader="false" EditMode="EditForms" AllowAutomaticInserts="true">

I tried like this:

protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
       {
           if (e.CommandName == RadGrid.UpdateCommandName)
           {
               if (e.Item is GridEditFormItem)
               {
                   GridEditFormItem item = (GridEditFormItem)e.Item;
                   int id = Convert.ToInt32(item.GetDataKeyValue("IdOsobe"));
                   if (id != 0)
                   {
                       RadTextBox txtInicijali =
                          (RadTextBox)item.FindControl("Inicijali");
 
                       RadGrid1.Rebind();
                   }
               }
           }
 
       }

But the value of txtInicijali.text is always string.empty.

How can get values from custom template?

Is there a better way to accomplish update from button outside the radgrid?

Another problem that I have:

I have defined <ItemTemplate></ItemTemplate> and <FormTemplate> and grid is in edit mode it shows both templates - does not hide itemtemplate! I want to item template and editformtemplate be the same.


Please help!

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Jan 2012, 06:03 AM
Hello,

Try the following code.
C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
  GridEditableItem editItem = e.Item as GridEditableItem;
  RadTextBox txt = (RadTextBox)editItem.FindControl("Inicijali");
}
When you are using custom FormTemplate, there is no need to specify EditMode in MasterTableView.

-Shinu.
Tags
Grid
Asked by
stonger
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or