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

Customized Edit from

2 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
prathyusha
Top achievements
Rank 1
prathyusha asked on 09 Nov 2011, 05:28 AM
Hi,

I have 2 Grids in the aspx page.

I am using Customized edit form (user control) for first Radgrid.

In the first grid we are using customized editform.  It has a link button. When the user clicks on  the link button , it  should bind the data to the second grid.

Is there any way can we achieve this.
Could some one plese help me regarding this.

Thanks
Usha

2 Answers, 1 is accepted

Sort by
0
Krishna Samaga
Top achievements
Rank 1
answered on 09 Nov 2011, 07:39 AM
On click of a link button or any other button for that matter, the grid event named OnItemCommand gets fired. You can handle this event and load your second grid.

If you have multiple buttons inside first grid and on click of each button, you want to do independent activities, then for each link button, pass unique CommandName and handle it based on this name in the same OnItemCommand event.

<

 

 

telerik:RadGrid ID="_grid" runat="server" OnItemCommand="_grid_ItemCommand">

 

 

 

<MasterTableView DataKeyNames="Id">

 

 

 

<Columns>

 

 

 

<telerik:GridTemplateColumn>

 

 

 

<ItemTemplate>

 

 

 

<asp:LinkButton ID="_btnBind" Text="Bind" runat="server" CommandName="CustomBind" />

 

<asp:LinkButton ID="_btnDownload" Text="Download" runat="server" CommandName="Download" />
</

 

 

ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

 

</telerik:RadGrid>

 

---------------------------------------------------------------------------------

 

 

protected void _grid_ItemCommand(object sender, GridCommandEventArgs e)

 

{

 

 

    if (e.CommandName == "Download")

 

    {
        //Do Download related functionality here

    }
    if (e.CommandName == "CustomBind")

 

    {
        //Do binding related functionality here

    }

 

 

}

0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Nov 2011, 07:58 AM
Hello,
WebForm1.aspx
<div>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
       </telerik:RadScriptManager>
       <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
           OnNeedDataSource="RadGrid1_NeedDataSource"
           onitemdatabound="RadGrid1_ItemDataBound"
           onitemcommand="RadGrid1_ItemCommand">
           <MasterTableView>
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                   </telerik:GridBoundColumn>
                   <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
               </Columns>
               <EditFormSettings UserControlName="WebUserControl1.ascx" EditFormType="WebUserControl">
                   <EditColumn UniqueName="EditCommandColumn1">
                   </EditColumn>
               </EditFormSettings>
           </MasterTableView>
       </telerik:RadGrid>
       <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" >
           <MasterTableView>
               <Columns>
                  <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                   </telerik:GridBoundColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
   </div>

WebForm1.aspx.cs
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
                new { ID = 1, Name = "Name1"},
                new { ID = 2, Name = "Name2"}
                
            };
            RadGrid1.DataSource = data;
        }
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode && e.Item is GridEditableItem)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
                LinkButton LinkButton1 = userControl.FindControl("LinkButton1") as LinkButton;
                LinkButton1.Text = "My text";
            }
        }
 
        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "MyCommand")
            {
                dynamic data = new[] {
                new { ID = 1, Name = "Name_" + e.CommandArgument},
                new { ID = 2, Name = "Name_" + e.CommandArgument}
                
            };
                RadGrid2.DataSource = data;
                RadGrid2.DataBind();
            }
        }

WebUserControl1.ascx
<div>
    <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ID" ) %>'>>
    </asp:Label>
    <br />
    <asp:LinkButton ID="LinkButton1" runat="server" CommandName="MyCommand" CommandArgument='<%# DataBinder.Eval( Container, "DataItem.ID" ) %>' Text="bind Second Grid">
    </asp:LinkButton>
</div>




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