locked
Read GridView data into string RRS feed

  • Question

  • I want to Read gridview data into string variable.

    for that i have written this code-


                        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                        GrdLeaveApproval.RenderControl(htmlWrite);   //This line giving me error

                        string strData = stringWrite.GetStringBuilder().ToString();

     

    Error- 

    Control 'ctl00_ctl23_g_61c52444_73b6_429b_9646_6128e3dd9459_ctl00_GrdLeaveApproval' of type 'GridView' must be placed inside a form tag with runat=server.

    Suggest me how can i resolve this problem.

     

    Thank's in advance

    Monday, October 3, 2011 8:55 AM

All replies

  • Hi Jitendra,

    The control 'ctl00_ctl23_g_61c52444_73b6_429b_9646_6128e3dd9459_ctl00_GrdLeaveApproval' is a server control, it must be run in a Form tag with runat=server.

    For example,

    <form runat=server>

    <SharePoint:SPGridControl ID=XXXX />

    <form>

    So, to fix the issue, please add the form tag with runat=server around your control tag.

    Thanks,
    Jinchun Chen


    Jinchun Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)
    Tuesday, October 4, 2011 10:22 AM
    Moderator
  • Actually my GridView in UserControl, so there is no need to add Form tag.
    Thursday, October 6, 2011 3:19 AM
  • Hi Jitendra,

    If I am right, you added the UserControl to a page. But is the UserControl within a Form tag?

    Thanks,
    Jinchun Chen


    Jinchun Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)
    Thursday, October 6, 2011 3:23 AM
    Moderator