Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
335
UltraWebGrid using User Control in a RowEditTemplate
posted

Hi all,

I am new to the UltraWebGrid and need some assistance understanding how the grid interacts with a user control that is used as the RowEditTemplate. I have defined a very simple user control, for my testing, that contains a textbox, 2 dropdowns, and a checkbox. In the user control's Page_Load event I load the data for my drop downs.

I have also loaded the user control as a template and have associated the user control with the grid's RowEditTemplate.

When I double click on the row in the grid, the template comes up and my drop downs are populated, but not selected. My questions are:

  1. I need to retrieve additional information from the database for the row that is being editted and add that data to the user control. What event can I use to do this? Would it be an event on the grid or on the user control? Can I access the grid's DataKey's from the user control?
  2. I need to populate the user control with the row that was selected. I see the columnKey attribute, but it only seems to work for controls of type textbox. How do I handle the checkbox and dropdown controls?
  3. Can I put validators on the user control, that can validate my user's input?

Is this documented anywhere?

Thanks

Parents
  • 45049
    Suggested Answer
    posted

    The most important point I can mention here is that the row edit template of WebGrid essentially has no server-side presence.  The template is discarded and recreated on each postback.  The best reason that I can think of to make use of a user control for a row edit template is if you want to re-use the same template for multiple WebGrid instances.

    sseelam said:
    1. I need to retrieve additional information from the database for the row that is being editted and add that data to the user control. What event can I use to do this? Would it be an event on the grid or on the user control? Can I access the grid's DataKey's from the user control?

    Ensure that your data is available to the grid.  If you don't want it displayed to the user in the grid normally, put it into a hidden column.  As for available events, see my answer to #2 below.

    sseelam said:
    2. I need to populate the user control with the row that was selected. I see the columnKey attribute, but it only seems to work for controls of type textbox. How do I handle the checkbox and dropdown controls?

    The columnKey attribute works for any HTML controls that use a "value" attribute to store their actual value, which includes a textbox (input type="text").

    For other controls, including your dropdown controls, you'll need to copy the data from the grid when the template is opened, and back from the template to the grid when the template is closed.  This process is described in the following article from our online Knowledge Base:
    HOWTO: Placing complex controls into the RowEditTemplate

    sseelam said:
    3. Can I put validators on the user control, that can validate my user's input?

    While I haven't myself recently tested this, I believe that this will work.  Remember that only client-side validation will be performed by ASP.NET validators in the row edit template.

Reply Children
No Data