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

Radgrid auto open in edit mode during page load

3 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 07 Aug 2014, 10:26 AM
Hi all,

Is there any way to auto open the Radgrid in the edit mode for the first record during page load?
The Radgrid is set to popup user control in edit mode...

Thank you.

Regards,
George




3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 07 Aug 2014, 11:39 AM
Hi George,

Please try the following code snippet to achieve your requirement.

C#:
void rgrdSample_PreRender(object sender, EventArgs e)
{   
  if (!IsPostBack)
  {          
    rgrdSample.Items[0].Edit = true;
    rgrdSample.Rebind();
  }      
}

Thanks,
Princy
0
George
Top achievements
Rank 1
answered on 08 Aug 2014, 12:27 AM
Hi Princy,

Thanks for the reply. But im getting below error for the line: gvMaster.Items(0).Edit = True

"Index was out of range. Must be non-negative and less than the size of the collection."
0
Princy
Top achievements
Rank 1
answered on 08 Aug 2014, 03:26 AM
Hi George,

Make sure that your Grid is having data and is bound in the NeedDataSource event. Please try the following sample code snippet and let me know if it works at your end. If you are not able to resolve the issue, provide your full code snippet.

ASPX:
<telerik:RadGrid ID="rgrdSample" runat="server" AutoGenerateColumns="false" OnNeedDataSource="rgrdSample_NeedDataSource" OnPreRender="rgrdSample_PreRender">
    <MasterTableView EditMode="PopUp">
       <Columns>
       <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" />
       <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" />
       <telerik:GridBoundColumn DataField="Number" HeaderText="Number" UniqueName="Number" />
       <telerik:GridEditCommandColumn>
       </telerik:GridEditCommandColumn>
       </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void rgrdSample_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
new { ID = 1, Name = "Name1", Number=123},
new { ID = 2, Name = "Name2", Number=234},
new { ID = 3, Name = "Name3", Number=234},
new { ID = 4, Name = "Name4", Number=456},
new { ID = 5, Name = "Name5", Number=567},
new { ID = 6, Name = "Name6", Number=567},
new { ID = 7, Name = "Name7", Number=789},
new { ID = 8, Name = "Name8", Number=896},
new { ID = 9, Name = "Name9", Number=741}
};
    rgrdSample.DataSource = data;
}
protected void rgrdSample_PreRender(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (rgrdSample.MasterTableView.Items.Count > 0)
        {
            rgrdSample.MasterTableView.Items[0].Edit = true;
            rgrdSample.Rebind();
        }
    }
}

Thanks,
Princy
Tags
Grid
Asked by
George
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
George
Top achievements
Rank 1
Share this question
or