using template columns

Discussion in 'ASP .Net Datagrid Control' started by Brett Wesoloski, Jan 8, 2007.

  1. I am new to using template columns. I am just trying to create a data grid
    with a bound column and another column with a imagebutton in it.

    What I have always done in the past was to then create a datatable and bind
    that to the datagrid.


    Where is my code to bind the grid to the datatable.
    DataTable dt = new DataTable();
    dt.Columns.Add("FundDescription");
    //dt.Columns.Add("F");

    PlanAssetCollection planAssets = PlanFactory.GetPlanAssets(18454);
    foreach (PlanAsset planAsset in planAssets)
    {
    if (planAsset.FundInfoLink != String.Empty)
    {
    DataRow dr = dt.NewRow();
    dr["FundDescription"] = planAsset.FundDescription;
    //dr["F"] = "F";

    dt.Rows.Add(dr);
    }

    }
    dgInvestmentInfo.DataSource = dt;
    dgInvestmentInfo.DataBind();


    Hear is the asp code to create the template columns.



    <asp:DataGrid id="dgInvestmentInfo" runat="server"
    AutoGenerateColumns="False">
    <Columns>
    <asp:TemplateColumn HeaderText="Fund Desc">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <font size="4">
    <%# DataBinder.Eval(Container.DataItem, "FundDescription") %>
    </font>
    /ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="F">
    <ItemTemplate>
    <asp:ImageButton id="F" onclick="F_Click" runat="server"
    ImageUrl="~images/signin.gif"></asp:ImageButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>

    I have also tried to add the CommandArgument to the asp:ImageButton
    CommandArgument='<%# DataBinder.Eval(Container.DataItem, "F") %>'
    CommandName="F" to the asp code and then add the extra column to the
    datatable. Didn't work.


    This is the error I get when I run the code.

    Error: Control '_ctl0_dgInvestmentInfo__ctl2_btnDel' of type 'Button' must
    be placed inside a form tag with runat=server.


    at System.Web.UI.Page.VerifyRenderingInServerForm(Control control)
    at System.Web.UI.WebControls.Button.AddAttributesToRender(HtmlTextWriter
    writer)
    at System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
    writer)
    at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    at System.Web.UI.Control.Render(HtmlTextWriter writer)
    at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    writer)
    at System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter
    writer)
    at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    at System.Web.UI.Control.Render(HtmlTextWriter writer)
    at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    writer)
    at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
    at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    at System.Web.UI.Control.Render(HtmlTextWriter writer)
    at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    writer)
    at System.Web.UI.WebControls.BaseDataList.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    at System.Web.UI.Control.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    at System.Web.UI.Control.Render(HtmlTextWriter writer)
    at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    writer)
    at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    at System.Web.UI.Control.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Page.ProcessRequestMain()



    Now if I just add another bound coulmn to the grid I can get it to work
    fine. It just seems to be when I add a imagebutton or any type of button
    for that matter.



    TIA,
    Brett
    Brett Wesoloski, Jan 8, 2007
    #1
    1. Advertising

  2. Ok I also should mention that I am trying to do all this in a user control
    which I place on a from. So the form does have the form tag with the runat =
    server.

    "Brett Wesoloski" <> wrote in message
    news:%...
    >I am new to using template columns. I am just trying to create a data grid
    >with a bound column and another column with a imagebutton in it.
    >
    > What I have always done in the past was to then create a datatable and
    > bind that to the datagrid.
    >
    >
    > Where is my code to bind the grid to the datatable.
    > DataTable dt = new DataTable();
    > dt.Columns.Add("FundDescription");
    > //dt.Columns.Add("F");
    >
    > PlanAssetCollection planAssets = PlanFactory.GetPlanAssets(18454);
    > foreach (PlanAsset planAsset in planAssets)
    > {
    > if (planAsset.FundInfoLink != String.Empty)
    > {
    > DataRow dr = dt.NewRow();
    > dr["FundDescription"] = planAsset.FundDescription;
    > //dr["F"] = "F";
    >
    > dt.Rows.Add(dr);
    > }
    >
    > }
    > dgInvestmentInfo.DataSource = dt;
    > dgInvestmentInfo.DataBind();
    >
    >
    > Hear is the asp code to create the template columns.
    >
    >
    >
    > <asp:DataGrid id="dgInvestmentInfo" runat="server"
    > AutoGenerateColumns="False">
    > <Columns>
    > <asp:TemplateColumn HeaderText="Fund Desc">
    > <ItemStyle HorizontalAlign="Center"></ItemStyle>
    > <ItemTemplate>
    > <font size="4">
    > <%# DataBinder.Eval(Container.DataItem, "FundDescription") %>
    > </font>
    > /ItemTemplate>
    > </asp:TemplateColumn>
    > <asp:TemplateColumn HeaderText="F">
    > <ItemTemplate>
    > <asp:ImageButton id="F" onclick="F_Click" runat="server"
    > ImageUrl="~images/signin.gif"></asp:ImageButton>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid>
    >
    > I have also tried to add the CommandArgument to the asp:ImageButton
    > CommandArgument='<%# DataBinder.Eval(Container.DataItem, "F") %>'
    > CommandName="F" to the asp code and then add the extra column to the
    > datatable. Didn't work.
    >
    >
    > This is the error I get when I run the code.
    >
    > Error: Control '_ctl0_dgInvestmentInfo__ctl2_btnDel' of type 'Button' must
    > be placed inside a form tag with runat=server.
    >
    >
    > at System.Web.UI.Page.VerifyRenderingInServerForm(Control control)
    > at System.Web.UI.WebControls.Button.AddAttributesToRender(HtmlTextWriter
    > writer)
    > at System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
    > writer)
    > at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > at System.Web.UI.Control.Render(HtmlTextWriter writer)
    > at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    > writer)
    > at System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter
    > writer)
    > at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > at System.Web.UI.Control.Render(HtmlTextWriter writer)
    > at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    > writer)
    > at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > at System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
    > at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > at System.Web.UI.Control.Render(HtmlTextWriter writer)
    > at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    > writer)
    > at System.Web.UI.WebControls.BaseDataList.Render(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > at System.Web.UI.Control.Render(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > at System.Web.UI.Control.Render(HtmlTextWriter writer)
    > at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    > writer)
    > at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > at System.Web.UI.Control.Render(HtmlTextWriter writer)
    > at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > at System.Web.UI.Page.ProcessRequestMain()
    >
    >
    >
    > Now if I just add another bound coulmn to the grid I can get it to work
    > fine. It just seems to be when I add a imagebutton or any type of button
    > for that matter.
    >
    >
    >
    > TIA,
    > Brett
    >
    >
    Brett Wesoloski, Jan 8, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. helpful sql
    Replies:
    0
    Views:
    807
    helpful sql
    May 19, 2005
  2. Replies:
    5
    Views:
    591
  3. Replies:
    4
    Views:
    933
  4. =?Utf-8?B?YmVub2l0?=

    Read CSV - string Columns - Int columns

    =?Utf-8?B?YmVub2l0?=, May 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    431
    =?Utf-8?B?YmVub2l0?=
    May 8, 2006
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    855
    Vinki
    Apr 25, 2007
Loading...

Share This Page