RadGrid - Open popup add form on page load

5 posts, 1 answers
  1. Fred
    Fred avatar
    11 posts
    Member since:
    Jun 2008

    Posted 20 Sep 2010 Link to this post

    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.

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Sep 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Fred
    Fred avatar
    11 posts
    Member since:
    Jun 2008

    Posted 21 Sep 2010 Link to this post

    Thank you!
  5. Aaron
    Aaron avatar
    9 posts
    Member since:
    Jun 2009

    Posted 20 Oct 2010 Link to this post

    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>
  6. Aaron
    Aaron avatar
    9 posts
    Member since:
    Jun 2009

    Posted 20 Oct 2010 Link to this post

    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;
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017