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

RadGrid - Open popup add form on page load

4 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 20 Sep 2010, 02:58 PM

Hi,

Is there a way to open a radgrid popup add form on page load? 

I want to reproduce the same action as when the user click "Add a new record" in the grid.

Thank you.

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Sep 2010, 05:18 AM
Hello Fred,

The following code snippet will be of help in opening the insert form when page loads.

Code:
protected void RadGrid1_PreRender(object sender, EventArgs e)
   
       RadGrid1.MasterTableView.IsItemInserted = true;
       RadGrid1.MasterTableView.Rebind(); 
   }


-Shinu.
0
Fred
Top achievements
Rank 1
answered on 21 Sep 2010, 03:53 PM
Thank you!
0
Aaron
Top achievements
Rank 2
answered on 20 Oct 2010, 10:13 PM
I'm doing the same thing, in my ItemCommand event, in my case i created a button column wich provides a unique command name, in this case "Printers", so, in my event, i evaluate the command name, and whenever its "Printers", i change my mastertable's usercontrol, and change it, and then open the pop up, but when trying to use eval, to retreive the current id, i get a blank string, but when i do this, using the edit column, and sending as command name "Edit", i get to retreive the data

protected void rgStations_ItemCommand(object source, GridCommandEventArgs e)
      {
          switch (e.CommandName)
          {
              case "InitInsert":
                  rgStations.MasterTableView.EditFormSettings.UserControlName = "~/UserControls/AddStations.ascx";
                  break;
              case "Edit":
                  rgStations.MasterTableView.EditFormSettings.UserControlName = "~/UserControls/EditStations.ascx";
                  break;
              case "Printers":
                  rgStations.MasterTableView.EditFormSettings.UserControlName = "~/UserControls/StationsPrinters.ascx";
                  rgStations.MasterTableView.IsItemInserted = true;
                  //rgStations.MasterTableView.Rebind();
                  break;
          }
          ObtenerEstaciones();//this is the method i use to retreive my data for the grid
      }

and i'm doing the databind like this

<asp:TextBox ID="txtSelectedStationValue" runat="server" Text='<%# Eval("Id") %>'></asp:TextBox>

and this is the radgrid's code

<telerik:RadGrid ID="rgStations" runat="server" Skin="Black" AllowPaging="True"
    AllowSorting="True" AutoGenerateColumns="False" GridLines="None"
    onitemcommand="rgStations_ItemCommand" >
      <MasterTableView CommandItemDisplay="Top" EditMode="PopUp">
        <RowIndicatorColumn>
          <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
 
        <ExpandCollapseColumn>
          <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
          <telerik:GridBoundColumn DataField="Id" HeaderText="Station Name"
          UniqueName="NameColumn">
          </telerik:GridBoundColumn>
          <telerik:GridBoundColumn DataField="Description" HeaderText="Description"
          UniqueName="DescriptionColumn">
          </telerik:GridBoundColumn>
          <telerik:GridBoundColumn DataField="Line" HeaderText="Line"
          UniqueName="LineColumn">
          </telerik:GridBoundColumn>
          <telerik:GridCheckBoxColumn DataField="IsMirror" DataType="System.Boolean"
          HeaderText="Is Mirror" UniqueName="IsMirrorColumn">
          </telerik:GridCheckBoxColumn>
            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Printers"
                HeaderText="Printers" ImageUrl="~/Resources/Icon_printers.png"
                UniqueName="PrintersColumn">
                <HeaderStyle HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />
            </telerik:GridButtonColumn>
          <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Edit"
          HeaderText="Edit" ImageUrl="~/Resources/Icon_edit.gif" UniqueName="EditColumn">
          </telerik:GridButtonColumn>
          <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
          ConfirmText="Are you sure you want to delete this row?" ConfirmTitle="Warning"
          HeaderText="Delete" ImageUrl="~/Resources/Icon_delete.gif" UniqueName="DeleteColumn">
          </telerik:GridButtonColumn>
        </Columns>
        <EditFormSettings EditFormType="WebUserControl"
        UserControlName="~/UserControls/EditStations.ascx">
          <PopUpSettings Modal="True" Height="300px" />
        </EditFormSettings>
      </MasterTableView>
      <ClientSettings>
        <ClientEvents OnPopUpShowing="PopUpShowing" />
        <Selecting AllowRowSelect="True" />
      </ClientSettings>
    </telerik:RadGrid>
0
Aaron
Top achievements
Rank 2
answered on 20 Oct 2010, 10:39 PM
Sorry, my bad, i just solved it, i just enabled the edit mode, and that was it

case "Printers":
                    e.Item.Edit = true;
                    rgStations.MasterTableView.EditFormSettings.UserControlName = "~/UserControls/StationsPrinters.ascx";
                    rgStations.MasterTableView.IsItemInserted = true;
                    //rgStations.MasterTableView.Rebind();
                    break;
Tags
Grid
Asked by
Fred
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Fred
Top achievements
Rank 1
Aaron
Top achievements
Rank 2
Share this question
or