Reference Assistance

11 posts, 0 answers
  1. Philip Senechal
    Philip Senechal avatar
    152 posts
    Member since:
    Apr 2008

    Posted 13 Jul 2010 Link to this post

    Need a little help here...I have a page within Sitefinity that is made up of 2 user controls. UserControl1 is the left half of the page, UserControl2 is the right side of the page. Each of these user controls have a RadGrid in them that open automatically in edit mode for a single record. I need to create a button inside UserControl2 that fires off the Update command for both RadGrids and then reloads the page so that both grids will return to edit mode with the new values.

    Can you tell me what the code behind would look like for that button to reference and fire off the update command on those grids inside the user controls? Thanks for the assistance.
  2. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 19 Jul 2010 Link to this post

    Hello Philip,

    Please check out the following online documentation article which explains how to fire command events from code:
    http://www.telerik.com/help/aspnet-ajax/grid-fire-command-event-from-code.html
    After raising command events you could try rebinding the RadGrids.

    Another approach could be to execute the update logic for the both grids into the button's click event handler. Then you could call the RadGrids' Rebind methods.

    Please give it try and let me know if you experience any problems.

    Greetings,
    Radoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Philip Senechal
    Philip Senechal avatar
    152 posts
    Member since:
    Apr 2008

    Posted 28 Jul 2010 Link to this post

    Thanks...that helps me to fire off the update command, but how do I actually reference the RadGrid in UserControl1 from UserControl2? Sitefinity is a bit different in that I can't add references to the two user controls on the page itself since the page is generated dynamically from Sitefinity.

    Maybe I need to explain it a bit differently. I have a page that I created within Sitefinity. I dropped two user controls on that page. One user control contains a RadGrid in edit mode, the other user control contains a button. When that button is pushed, I need to reference the RadGrid in the other user control so that I can fire off the update command.

    Right now I can't figure out how to gain access to objects in the other user control when the page is being generated by Sitefinity. I have found plenty of examples for a standard .NET page where I can create references to both user control pages, but the solutions don't work within Sitefinity.

    Thanks for the assistance and let me know if I can explain the situation any better.
  5. Philip Senechal
    Philip Senechal avatar
    152 posts
    Member since:
    Apr 2008

    Posted 02 Aug 2010 Link to this post

    Well...I ended up changing my page structure around since I couldn't get this figured out, so I now have the RadGrid and an ASP button in the same user control.

    I'm able to fire off the update command for the RadGrid using the FireCommandEvent method, but I'm having some problems in my UpdateCommand method.

    My UpdateCommand method looks like this right now...
    protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
     
        /*LINQ code to update items */
        Requests.RequestsDataContext db = new Requests.RequestsDataContext();
        Requests.tRequests request = db.tRequests.Single(p => p.ReqID == int.Parse(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ReqID"].ToString()));
        request.ReqTyp = int.Parse((item.FindControl("dd_ReqTyp") as RadComboBox).SelectedItem.Value);
        db.SubmitChanges();
     
        e.Item.OwnerTableView.Rebind();
    }

    So...everything works except getting the value of the RadComboBox "dd_ReqTyp". I get an object not found error. If I simply hard code a value into the request.ReqTyp = line, it works perfectly.

    Since I'm using the FireCommandEvent, do I need to look for objects in my edit template differently than what I'm using? I've always used item.FindControl() in the past and it's worked, so I'm not sure why it's not working now.

    Thanks for the help!
  6. Philip Senechal
    Philip Senechal avatar
    152 posts
    Member since:
    Apr 2008

    Posted 02 Aug 2010 Link to this post

    **UPDATE**

    I was doing some testing, and I'm finding that when I bring back the value of item.IsInEditMode, I get False. Is it thinking my grid isn't in Edit Mode and therefore can't find the RadComboBox on my Edit Form Template?

    The grid is opened in edit mode using the PreRender event and the following code:

    protected void RadGrid1_PreRender(object sender, EventArge e)
    {
        RadGrid1.EditIndexes.Add(0);
        RadGrid1.Rebind();
    }

    Shouldn't the RadGrid still be in edit mode when I use the FireCommandEvent method to fire off the UpdateCommand?
  7. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 03 Aug 2010 Link to this post

    Hello Philip,

    To achieve the desired functionality and find the RadComboBox with item.FindControl("dd_ReqTyp") you need to fire the Update command from the GridEditableItem. For example:
    <EditFormSettings EditFormType="Template">
      <FormTemplate>
    ...
      </FormTemplate>
    </EditFormSettings>
    ...
    <asp:Button runat="server" ID="testButton" Text="fireUpdate" OnClick="testButton_Click" />

    Code behind:
    protected void testButton_Click(object sender, EventArgs e)
    {
        GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem);
        for (int i = 0; i < items.Length; i++)
        {
            int itemIndex = items[i].ItemIndex;
            if (RadGrid1.EditItems[0].ItemIndex == itemIndex)
            {
                (items[i] as GridEditableItem).FireCommandEvent("Update", String.Empty);
            }
        }
    }

    Then into the RadGrid.UpdateCommand event handler you could find the RadComboBox with FindControl().
    Additionally you could try putting all items in edit mode without rebinding the RadGrid with the following code snippet:
    protected void Page_Load(object sender, EventArgs e)
    {
        for (int i = 0; i < RadGrid1.PageSize; i++)
        {
            RadGrid1.EditIndexes.Add(i);
        }
    }

    Please give it try and let me know if the issue still persists.

    Kind regards,
    Radoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Philip Senechal
    Philip Senechal avatar
    152 posts
    Member since:
    Apr 2008

    Posted 03 Aug 2010 Link to this post

    Thank you for the information, especially how to put the item in edit mode without rebinding.

    Question for you...I see that your code puts the button inside the GridEditableItem. Is there a possible way to use a button outside the grid to update a database with the changes in that GridEditableItem and then rebind the grid? I'm assuming that the code will have to be in the button_click event for the button outside of the grid. What do I need to do to gain access to the objects in that GridEditableItem from the button_click event outside the grid? How would I do an Ajax rebind of that grid when I'm done executing my database update code?

    Thanks again for the assistance!
  9. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 06 Aug 2010 Link to this post

    Hello Philip,

    The code snippet which I sent you with my previous ticket is valid for the button outside of the RadGrid too. Also to get all controls from the RadGrid's edit form items you could try using the following code snippet:
    <telerik:RadGrid runat="server" AllowMultiRowEdit="true" AutoGenerateEditColumn="true" ID="RadGrid1" AutoGenerateColumns="false">
     <MasterTableView>
        <Columns>
          <telerik:GridBoundColumn DataField="ID" HeaderText="ID">
          </telerik:GridBoundColumn>
          <telerik:GridBoundColumn DataField="Item" HeaderText="Item">
          </telerik:GridBoundColumn>
          <telerik:GridBoundColumn DataField="Date" HeaderText="Date">
          </telerik:GridBoundColumn>
        </Columns>
      </MasterTableView>
      </telerik:RadGrid>
     <asp:Button runat="server" ID="Button1" />

    void Button1_Click(object sender, EventArgs e)
    {
       GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem);
       foreach (GridEditFormItem item in items)
       {
           if (item["ID"].Controls.Count > 0)
           {
              TextBox tbID = item["ID"].Controls[0] as TextBox;
              TextBox tbItem = item["Item"].Controls[0] as TextBox;
              TextBox tbDate = item["Date"].Controls[0] as TextBox;
                  
              // Update database with values from textboxes.
           }
        }
    RadGrid1.EditIndexes.Clear();
    RadGrid1.Rebind();
    }

    Please give it try and let me know if it helps you.

    Sincerely yours,
    Radoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Philip Senechal
    Philip Senechal avatar
    152 posts
    Member since:
    Apr 2008

    Posted 06 Aug 2010 Link to this post

    Thank you Radoslav, I had completely misunderstood your previous posting and thought my button had to be in the EditFormTemplate, not that I had to just gain access to the EditFormTemplate and fire the command from within it.

    Your code worked perfectly and I'm able to update my items. The only issue now that I'm working on is that after the rebind, my grid is not returning to edit mode. I think I can figure that out though.

    Thanks again for all your assistance!
  11. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 11 Aug 2010 Link to this post

    Hi Philip,

    I am glad that you achieved the desired functionality.

    Additionally you could try opening the edit form manually on Page_Load event with the following code:
    RadGrid1.EditIndexes.Add(itemIndex);

    If you need further assistance, do not hesitate to contact us again.

    Sincerely yours,
    Radoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. KARAN
    KARAN avatar
    12 posts
    Member since:
    May 2011

    Posted 15 Jun 2011 Link to this post

    Hello pls,..

    Need help..I have two user controls in a single page. But I want to see second usercontrol while first usercontrol is in hide , vice versa..

    what I have to do for that,.shall I have to create code in usercontrol or set any property in page..Can you send code for this..

    pls help me
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017