Find footer labels in DataGrid

Discussion in 'ASP .Net' started by tshad, Nov 3, 2004.

  1. tshad

    tshad Guest

    How do I find (and set) a couple of labels in the Footer after a DataGrid is
    filled?

    I have a bunch of DataGrids that get displayed nested inside a DataList.

    The datagrid looks like:

    *******************************************************************************
    <asp:DataGrid visible="False"
    border=1
    id="DataGrid1"
    runat="server"
    Width="400px"
    Height="79px"
    AutoGenerateColumns="False"
    GridLines="None"
    ShowFooter="true"
    onItemDataBound="DataGrid1_ItemDataBound"
    OnItemCommand="DataInsert"
    onEditCommand="DataEdit"
    onCancelCommand="DataCancel"
    onUpdateCommand="DataUpdate">
    <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
    BorderColor="White" BackColor="linen"></AlternatingItemStyle>
    <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
    <Columns>
    <asp:TemplateColumn HeaderText="Answer">
    <ItemTemplate>
    <asp:Label id="lblAnswer" runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Answer") %>'>
    </asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
    </FooterTemplate>
    <EditItemTemplate>
    <asp:textbox id="txtAnswer" runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Answer") %>'>
    </asp:textbox>
    </EditItemTemplate>
    </asp:templateColumn>
    <asp:TemplateColumn >
    <ItemTemplate>
    <asp:Label id="lblPositionID" runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    </asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:Label id="lblPositionIDFooter" runat="server">
    </asp:Label>
    </FooterTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn >
    <ItemTemplate>
    <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    </asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:Label id="lblQuestionUniqueFooter" runat="server">
    </asp:Label>
    </FooterTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"
    HeaderText="AnswerUnique"></asp:BoundColumn>
    <asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'
    id='textbox1'>" visible="true"
    ButtonType="LinkButton"
    UpdateText="<img src='..\images\update.png' border='0'>"
    CancelText="<img src='..\images\Cancel.png' border='0'>" />
    <asp:TemplateColumn >
    <FooterTemplate>
    <asp:LinkButton CommandName="Insert" Text="<img
    src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
    </FooterTemplate>
    <ItemTemplate>
    <asp:LinkButton CommandName="Delete" Text="<img
    src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>
    ***************************************************************************************

    I have the DataGrid by doing something like:

    for each oItem as DataListItem in DataList1.Items
    Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)

    How would I use oGrid to find and set "lblPositionIDFooter" and
    "lblQuestionUniqueFooter"?

    I need this as I need a place to put the PositionID and QuestionUnique as
    they are keys I need to use in my Insert statement. I am inserting rows
    from the Footer and need to get these variables from some where, so this
    seems to be the most logical place to store them.

    Thanks,

    Tom.
     
    tshad, Nov 3, 2004
    #1
    1. Advertising

  2. tshad

    Sonu Kapoor Guest

    Try: e.Item.FindControl("lblPositionIDFooter)

    Sonu


    >-----Original Message-----
    >How do I find (and set) a couple of labels in the Footer

    after a DataGrid is
    >filled?
    >
    >I have a bunch of DataGrids that get displayed nested

    inside a DataList.
    >
    >The datagrid looks like:
    >
    >**********************************************************

    *********************
    ><asp:DataGrid visible="False"
    > border=1
    > id="DataGrid1"
    > runat="server"
    > Width="400px"
    > Height="79px"
    > AutoGenerateColumns="False"
    > GridLines="None"
    > ShowFooter="true"
    > onItemDataBound="DataGrid1_ItemDataBound"
    > OnItemCommand="DataInsert"
    > onEditCommand="DataEdit"
    > onCancelCommand="DataCancel"
    > onUpdateCommand="DataUpdate">
    > <AlternatingItemStyle BorderWidth="0px"

    BorderStyle="None"
    >BorderColor="White"

    BackColor="linen"></AlternatingItemStyle>
    > <HeaderStyle Font-Bold="True"

    BackColor="#6699cc"></HeaderStyle>
    > <Columns>
    > <asp:TemplateColumn HeaderText="Answer">
    > <ItemTemplate>
    > <asp:Label id="lblAnswer" runat="server" Text='<%#
    >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:TextBox id="txtAnswerFooter"

    runat="server"></asp:TextBox>
    > </FooterTemplate>
    > <EditItemTemplate>
    > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > </asp:textbox>
    > </EditItemTemplate>
    > </asp:templateColumn>
    > <asp:TemplateColumn >
    > <ItemTemplate>
    > <asp:Label id="lblPositionID" runat="server" Text='<%

    #
    >DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:Label id="lblPositionIDFooter" runat="server">
    > </asp:Label>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    > <asp:TemplateColumn >
    > <ItemTemplate>
    > <asp:Label id="lblQuestionUnique" runat="server"

    Text='<%#
    >DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:Label id="lblQuestionUniqueFooter"

    runat="server">
    > </asp:Label>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    > <asp:BoundColumn DataField="AnswerUnique"

    visible="false" ReadOnly="true"
    >HeaderText="AnswerUnique"></asp:BoundColumn>
    > <asp:EditCommandColumn EditText="<img

    src='..\images\Edit.png'border='0'
    >id='textbox1'>" visible="true"
    > ButtonType="LinkButton"
    > UpdateText="<img src='..\images\update.png'

    border='0'>"
    >CancelText="<img src='..\images\Cancel.png'

    border='0'>" />
    > <asp:TemplateColumn >
    > <FooterTemplate>
    > <asp:LinkButton CommandName="Insert" Text="<img
    >src='..\images\Add.gif'border='0'>" ID="btnAdd"

    Runat="server" />
    > </FooterTemplate>
    > <ItemTemplate>
    > <asp:LinkButton CommandName="Delete" Text="<img
    >src='..\images\Delete.gif'border='0'>" ID="btnDel"

    Runat="server" />
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    ></asp:DataGrid>
    >**********************************************************

    *****************************
    >
    >I have the DataGrid by doing something like:
    >
    > for each oItem as DataListItem in DataList1.Items
    > Dim oGrid as DataGrid = CType(oItem.FindControl

    ("DataGrid1"),DataGrid)
    >
    >How would I use oGrid to find and

    set "lblPositionIDFooter" and
    >"lblQuestionUniqueFooter"?
    >
    >I need this as I need a place to put the PositionID and

    QuestionUnique as
    >they are keys I need to use in my Insert statement. I am

    inserting rows
    >from the Footer and need to get these variables from some

    where, so this
    >seems to be the most logical place to store them.
    >
    >Thanks,
    >
    >Tom.
    >
    >
    >.
    >
     
    Sonu Kapoor, Nov 3, 2004
    #2
    1. Advertising

  3. tshad

    Saravana Guest

    First you need to check whether that datagrid item is footer, then you can
    use e.item.cells(<correspondingcell index>.findcontrol(<your control name>)
    method to find your label control. For more details, refer this link
    http://www.extremeexperts.com/Net/Articles/AddingControlstoFooter.aspx

    --
    Saravana
    http://dotnetjunkies.com/WebLog/saravana/
    www.ExtremeExperts.com


    "tshad" <> wrote in message
    news:...
    > How do I find (and set) a couple of labels in the Footer after a DataGrid

    is
    > filled?
    >
    > I have a bunch of DataGrids that get displayed nested inside a DataList.
    >
    > The datagrid looks like:
    >
    >

    ****************************************************************************
    ***
    > <asp:DataGrid visible="False"
    > border=1
    > id="DataGrid1"
    > runat="server"
    > Width="400px"
    > Height="79px"
    > AutoGenerateColumns="False"
    > GridLines="None"
    > ShowFooter="true"
    > onItemDataBound="DataGrid1_ItemDataBound"
    > OnItemCommand="DataInsert"
    > onEditCommand="DataEdit"
    > onCancelCommand="DataCancel"
    > onUpdateCommand="DataUpdate">
    > <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
    > BorderColor="White" BackColor="linen"></AlternatingItemStyle>
    > <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
    > <Columns>
    > <asp:TemplateColumn HeaderText="Answer">
    > <ItemTemplate>
    > <asp:Label id="lblAnswer" runat="server" Text='<%#
    > DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
    > </FooterTemplate>
    > <EditItemTemplate>
    > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    > DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > </asp:textbox>
    > </EditItemTemplate>
    > </asp:templateColumn>
    > <asp:TemplateColumn >
    > <ItemTemplate>
    > <asp:Label id="lblPositionID" runat="server" Text='<%#
    > DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:Label id="lblPositionIDFooter" runat="server">
    > </asp:Label>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    > <asp:TemplateColumn >
    > <ItemTemplate>
    > <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
    > DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:Label id="lblQuestionUniqueFooter" runat="server">
    > </asp:Label>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    > <asp:BoundColumn DataField="AnswerUnique" visible="false"

    ReadOnly="true"
    > HeaderText="AnswerUnique"></asp:BoundColumn>
    > <asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'
    > id='textbox1'>" visible="true"
    > ButtonType="LinkButton"
    > UpdateText="<img src='..\images\update.png' border='0'>"
    > CancelText="<img src='..\images\Cancel.png' border='0'>" />
    > <asp:TemplateColumn >
    > <FooterTemplate>
    > <asp:LinkButton CommandName="Insert" Text="<img
    > src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
    > </FooterTemplate>
    > <ItemTemplate>
    > <asp:LinkButton CommandName="Delete" Text="<img
    > src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid>
    >

    ****************************************************************************
    ***********
    >
    > I have the DataGrid by doing something like:
    >
    > for each oItem as DataListItem in DataList1.Items
    > Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)
    >
    > How would I use oGrid to find and set "lblPositionIDFooter" and
    > "lblQuestionUniqueFooter"?
    >
    > I need this as I need a place to put the PositionID and QuestionUnique as
    > they are keys I need to use in my Insert statement. I am inserting rows
    > from the Footer and need to get these variables from some where, so this
    > seems to be the most logical place to store them.
    >
    > Thanks,
    >
    > Tom.
    >
    >
     
    Saravana, Nov 3, 2004
    #3
  4. tshad

    Scott Allen Guest

    Hi tshad:

    You might want to try during the ItemDataBound event instead (check
    for e.Item.ItemType == ListItemType.Footer).

    If you need to wait until afterwards, then you can index into the
    Controls collection of the grid. (The Items collection might look
    tempting at first, but it only contains DataGridItems bound to
    records, the header and footer items appear only in the Controls
    collection). The footer item should be in the last element of the
    Controls array.

    I have some examples about 1/2 through this article:
    http://www.odetocode.com/Articles/116.aspx

    HTH,

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/




    On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
    <> wrote:

    >How do I find (and set) a couple of labels in the Footer after a DataGrid is
    >filled?
    >
    >I have a bunch of DataGrids that get displayed nested inside a DataList.
    >
    >The datagrid looks like:
    >
    >*******************************************************************************
    ><asp:DataGrid visible="False"
    > border=1
    > id="DataGrid1"
    > runat="server"
    > Width="400px"
    > Height="79px"
    > AutoGenerateColumns="False"
    > GridLines="None"
    > ShowFooter="true"
    > onItemDataBound="DataGrid1_ItemDataBound"
    > OnItemCommand="DataInsert"
    > onEditCommand="DataEdit"
    > onCancelCommand="DataCancel"
    > onUpdateCommand="DataUpdate">
    > <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
    >BorderColor="White" BackColor="linen"></AlternatingItemStyle>
    > <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
    > <Columns>
    > <asp:TemplateColumn HeaderText="Answer">
    > <ItemTemplate>
    > <asp:Label id="lblAnswer" runat="server" Text='<%#
    >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
    > </FooterTemplate>
    > <EditItemTemplate>
    > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > </asp:textbox>
    > </EditItemTemplate>
    > </asp:templateColumn>
    > <asp:TemplateColumn >
    > <ItemTemplate>
    > <asp:Label id="lblPositionID" runat="server" Text='<%#
    >DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:Label id="lblPositionIDFooter" runat="server">
    > </asp:Label>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    > <asp:TemplateColumn >
    > <ItemTemplate>
    > <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
    >DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:Label id="lblQuestionUniqueFooter" runat="server">
    > </asp:Label>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    > <asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"
    >HeaderText="AnswerUnique"></asp:BoundColumn>
    > <asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'
    >id='textbox1'>" visible="true"
    > ButtonType="LinkButton"
    > UpdateText="<img src='..\images\update.png' border='0'>"
    >CancelText="<img src='..\images\Cancel.png' border='0'>" />
    > <asp:TemplateColumn >
    > <FooterTemplate>
    > <asp:LinkButton CommandName="Insert" Text="<img
    >src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
    > </FooterTemplate>
    > <ItemTemplate>
    > <asp:LinkButton CommandName="Delete" Text="<img
    >src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    ></asp:DataGrid>
    >***************************************************************************************
    >
    >I have the DataGrid by doing something like:
    >
    > for each oItem as DataListItem in DataList1.Items
    > Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)
    >
    >How would I use oGrid to find and set "lblPositionIDFooter" and
    >"lblQuestionUniqueFooter"?
    >
    >I need this as I need a place to put the PositionID and QuestionUnique as
    >they are keys I need to use in my Insert statement. I am inserting rows
    >from the Footer and need to get these variables from some where, so this
    >seems to be the most logical place to store them.
    >
    >Thanks,
    >
    >Tom.
    >
     
    Scott Allen, Nov 3, 2004
    #4
  5. tshad

    tshad Guest

    "Sonu Kapoor" <> wrote in message
    news:391501c4c14a$fb82cad0$...
    > Try: e.Item.FindControl("lblPositionIDFooter)


    I can't use e.item as the object is a datalist that has a datagrid in it. I
    then find the oGrid from that.

    So I tried:

    Dim fPositionID as Label = oGrid.Item.FindControl("lblPositionIDFooter")

    and got the following error message:
    ************************************************
    Compiler Error Message: BC30456: 'Item' is not a member of
    'System.Web.UI.WebControls.DataGrid'.

    Source Error:

    Line 225: Dim oCollapse as ImageButton =
    CType(DataList1.Items(DataList1.SelectedIndex).FindControl("CollapseButton")
    ,ImageButton)
    Line 226:
    Line 227: Dim fPositionID as Label =
    oGrid.Item.FindControl("lblPositionIDFooter")
    *****************************************************************

    Tom.
    >
    > Sonu
    >
    >
    > >-----Original Message-----
    > >How do I find (and set) a couple of labels in the Footer

    > after a DataGrid is
    > >filled?
    > >
    > >I have a bunch of DataGrids that get displayed nested

    > inside a DataList.
    > >
    > >The datagrid looks like:
    > >
    > >**********************************************************

    > *********************
    > ><asp:DataGrid visible="False"
    > > border=1
    > > id="DataGrid1"
    > > runat="server"
    > > Width="400px"
    > > Height="79px"
    > > AutoGenerateColumns="False"
    > > GridLines="None"
    > > ShowFooter="true"
    > > onItemDataBound="DataGrid1_ItemDataBound"
    > > OnItemCommand="DataInsert"
    > > onEditCommand="DataEdit"
    > > onCancelCommand="DataCancel"
    > > onUpdateCommand="DataUpdate">
    > > <AlternatingItemStyle BorderWidth="0px"

    > BorderStyle="None"
    > >BorderColor="White"

    > BackColor="linen"></AlternatingItemStyle>
    > > <HeaderStyle Font-Bold="True"

    > BackColor="#6699cc"></HeaderStyle>
    > > <Columns>
    > > <asp:TemplateColumn HeaderText="Answer">
    > > <ItemTemplate>
    > > <asp:Label id="lblAnswer" runat="server" Text='<%#
    > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:TextBox id="txtAnswerFooter"

    > runat="server"></asp:TextBox>
    > > </FooterTemplate>
    > > <EditItemTemplate>
    > > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > </asp:textbox>
    > > </EditItemTemplate>
    > > </asp:templateColumn>
    > > <asp:TemplateColumn >
    > > <ItemTemplate>
    > > <asp:Label id="lblPositionID" runat="server" Text='<%

    > #
    > >DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:Label id="lblPositionIDFooter" runat="server">
    > > </asp:Label>
    > > </FooterTemplate>
    > > </asp:TemplateColumn>
    > > <asp:TemplateColumn >
    > > <ItemTemplate>
    > > <asp:Label id="lblQuestionUnique" runat="server"

    > Text='<%#
    > >DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:Label id="lblQuestionUniqueFooter"

    > runat="server">
    > > </asp:Label>
    > > </FooterTemplate>
    > > </asp:TemplateColumn>
    > > <asp:BoundColumn DataField="AnswerUnique"

    > visible="false" ReadOnly="true"
    > >HeaderText="AnswerUnique"></asp:BoundColumn>
    > > <asp:EditCommandColumn EditText="<img

    > src='..\images\Edit.png'border='0'
    > >id='textbox1'>" visible="true"
    > > ButtonType="LinkButton"
    > > UpdateText="<img src='..\images\update.png'

    > border='0'>"
    > >CancelText="<img src='..\images\Cancel.png'

    > border='0'>" />
    > > <asp:TemplateColumn >
    > > <FooterTemplate>
    > > <asp:LinkButton CommandName="Insert" Text="<img
    > >src='..\images\Add.gif'border='0'>" ID="btnAdd"

    > Runat="server" />
    > > </FooterTemplate>
    > > <ItemTemplate>
    > > <asp:LinkButton CommandName="Delete" Text="<img
    > >src='..\images\Delete.gif'border='0'>" ID="btnDel"

    > Runat="server" />
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > </Columns>
    > ></asp:DataGrid>
    > >**********************************************************

    > *****************************
    > >
    > >I have the DataGrid by doing something like:
    > >
    > > for each oItem as DataListItem in DataList1.Items
    > > Dim oGrid as DataGrid = CType(oItem.FindControl

    > ("DataGrid1"),DataGrid)
    > >
    > >How would I use oGrid to find and

    > set "lblPositionIDFooter" and
    > >"lblQuestionUniqueFooter"?
    > >
    > >I need this as I need a place to put the PositionID and

    > QuestionUnique as
    > >they are keys I need to use in my Insert statement. I am

    > inserting rows
    > >from the Footer and need to get these variables from some

    > where, so this
    > >seems to be the most logical place to store them.
    > >
    > >Thanks,
    > >
    > >Tom.
    > >
    > >
    > >.
    > >
     
    tshad, Nov 3, 2004
    #5
  6. tshad

    tshad Guest

    "Saravana" <> wrote in message
    news:yD_hd.2189$...
    > First you need to check whether that datagrid item is footer, then you can
    > use e.item.cells(<correspondingcell index>.findcontrol(<your control

    name>)
    > method to find your label control. For more details, refer this link
    > http://www.extremeexperts.com/Net/Articles/AddingControlstoFooter.aspx


    I already know I have a footer and I have the Grid object. I just don't
    know how to get to a label that is already in the footer.

    Tom.
    >
    > --
    > Saravana
    > http://dotnetjunkies.com/WebLog/saravana/
    > www.ExtremeExperts.com
    >
    >
    > "tshad" <> wrote in message
    > news:...
    > > How do I find (and set) a couple of labels in the Footer after a

    DataGrid
    > is
    > > filled?
    > >
    > > I have a bunch of DataGrids that get displayed nested inside a DataList.
    > >
    > > The datagrid looks like:
    > >
    > >

    >

    ****************************************************************************
    > ***
    > > <asp:DataGrid visible="False"
    > > border=1
    > > id="DataGrid1"
    > > runat="server"
    > > Width="400px"
    > > Height="79px"
    > > AutoGenerateColumns="False"
    > > GridLines="None"
    > > ShowFooter="true"
    > > onItemDataBound="DataGrid1_ItemDataBound"
    > > OnItemCommand="DataInsert"
    > > onEditCommand="DataEdit"
    > > onCancelCommand="DataCancel"
    > > onUpdateCommand="DataUpdate">
    > > <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
    > > BorderColor="White" BackColor="linen"></AlternatingItemStyle>
    > > <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
    > > <Columns>
    > > <asp:TemplateColumn HeaderText="Answer">
    > > <ItemTemplate>
    > > <asp:Label id="lblAnswer" runat="server" Text='<%#
    > > DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
    > > </FooterTemplate>
    > > <EditItemTemplate>
    > > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    > > DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > </asp:textbox>
    > > </EditItemTemplate>
    > > </asp:templateColumn>
    > > <asp:TemplateColumn >
    > > <ItemTemplate>
    > > <asp:Label id="lblPositionID" runat="server" Text='<%#
    > > DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:Label id="lblPositionIDFooter" runat="server">
    > > </asp:Label>
    > > </FooterTemplate>
    > > </asp:TemplateColumn>
    > > <asp:TemplateColumn >
    > > <ItemTemplate>
    > > <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
    > > DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:Label id="lblQuestionUniqueFooter" runat="server">
    > > </asp:Label>
    > > </FooterTemplate>
    > > </asp:TemplateColumn>
    > > <asp:BoundColumn DataField="AnswerUnique" visible="false"

    > ReadOnly="true"
    > > HeaderText="AnswerUnique"></asp:BoundColumn>
    > > <asp:EditCommandColumn EditText="<img

    src='..\images\Edit.png'border='0'
    > > id='textbox1'>" visible="true"
    > > ButtonType="LinkButton"
    > > UpdateText="<img src='..\images\update.png' border='0'>"
    > > CancelText="<img src='..\images\Cancel.png' border='0'>" />
    > > <asp:TemplateColumn >
    > > <FooterTemplate>
    > > <asp:LinkButton CommandName="Insert" Text="<img
    > > src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
    > > </FooterTemplate>
    > > <ItemTemplate>
    > > <asp:LinkButton CommandName="Delete" Text="<img
    > > src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > </Columns>
    > > </asp:DataGrid>
    > >

    >

    ****************************************************************************
    > ***********
    > >
    > > I have the DataGrid by doing something like:
    > >
    > > for each oItem as DataListItem in DataList1.Items
    > > Dim oGrid as DataGrid =

    CType(oItem.FindControl("DataGrid1"),DataGrid)
    > >
    > > How would I use oGrid to find and set "lblPositionIDFooter" and
    > > "lblQuestionUniqueFooter"?
    > >
    > > I need this as I need a place to put the PositionID and QuestionUnique

    as
    > > they are keys I need to use in my Insert statement. I am inserting rows
    > > from the Footer and need to get these variables from some where, so this
    > > seems to be the most logical place to store them.
    > >
    > > Thanks,
    > >
    > > Tom.
    > >
    > >

    >
    >
     
    tshad, Nov 3, 2004
    #6
  7. tshad

    tshad Guest

    "Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    news:eek:...
    > Hi tshad:
    >
    > You might want to try during the ItemDataBound event instead (check
    > for e.Item.ItemType == ListItemType.Footer).
    >
    > If you need to wait until afterwards, then you can index into the
    > Controls collection of the grid. (The Items collection might look
    > tempting at first, but it only contains DataGridItems bound to
    > records, the header and footer items appear only in the Controls
    > collection). The footer item should be in the last element of the
    > Controls array.
    >
    > I have some examples about 1/2 through this article:
    > http://www.odetocode.com/Articles/116.aspx


    I tried some of what you had and here is what I came up with.

    The routine where I need to get access to the label in the footer is:

    **********************************************************************
    Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
    if e.CommandName = "Select" then
    DataList1.SelectedIndex = e.Item.ItemIndex
    end if

    Dim oGrid as DataGrid =
    CType(DataList1.Items(DataList1.SelectedIndex).FindControl("DataGrid1"),Data
    Grid)

    Dim lblPositionIDF as Label =
    oGrid.Controls(0).Controls(0).FindControl("lblPositionIDFooter")
    **********************************************************************

    Gives me the following error:

    Specified argument was out of the range of valid values. Parameter name:
    index

    The DataGrid footer section looks like:

    **********************************************************************
    <asp:TemplateColumn visible="true">
    <ItemTemplate>
    <asp:Label id="lblPositionID" runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    </asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:Label id="lblPositionIDFooter" runat="server">
    </asp:Label>
    </FooterTemplate>
    </asp:TemplateColumn>
    **********************************************************************

    This doesn't seem to be it, unless I am missing something (and I probably
    am).

    Thanks,

    Tom.

    >
    > HTH,
    >
    > --
    > Scott
    > http://www.OdeToCode.com/blogs/scott/
    >
    >
    >
    >
    > On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
    > <> wrote:
    >
    > >How do I find (and set) a couple of labels in the Footer after a DataGrid

    is
    > >filled?
    > >
    > >I have a bunch of DataGrids that get displayed nested inside a DataList.
    > >
    > >The datagrid looks like:
    > >

    >
    >***************************************************************************

    ****
    > ><asp:DataGrid visible="False"
    > > border=1
    > > id="DataGrid1"
    > > runat="server"
    > > Width="400px"
    > > Height="79px"
    > > AutoGenerateColumns="False"
    > > GridLines="None"
    > > ShowFooter="true"
    > > onItemDataBound="DataGrid1_ItemDataBound"
    > > OnItemCommand="DataInsert"
    > > onEditCommand="DataEdit"
    > > onCancelCommand="DataCancel"
    > > onUpdateCommand="DataUpdate">
    > > <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
    > >BorderColor="White" BackColor="linen"></AlternatingItemStyle>
    > > <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
    > > <Columns>
    > > <asp:TemplateColumn HeaderText="Answer">
    > > <ItemTemplate>
    > > <asp:Label id="lblAnswer" runat="server" Text='<%#
    > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
    > > </FooterTemplate>
    > > <EditItemTemplate>
    > > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > </asp:textbox>
    > > </EditItemTemplate>
    > > </asp:templateColumn>
    > > <asp:TemplateColumn >
    > > <ItemTemplate>
    > > <asp:Label id="lblPositionID" runat="server" Text='<%#
    > >DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:Label id="lblPositionIDFooter" runat="server">
    > > </asp:Label>
    > > </FooterTemplate>
    > > </asp:TemplateColumn>
    > > <asp:TemplateColumn >
    > > <ItemTemplate>
    > > <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
    > >DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > <FooterTemplate>
    > > <asp:Label id="lblQuestionUniqueFooter" runat="server">
    > > </asp:Label>
    > > </FooterTemplate>
    > > </asp:TemplateColumn>
    > > <asp:BoundColumn DataField="AnswerUnique" visible="false"

    ReadOnly="true"
    > >HeaderText="AnswerUnique"></asp:BoundColumn>
    > > <asp:EditCommandColumn EditText="<img

    src='..\images\Edit.png'border='0'
    > >id='textbox1'>" visible="true"
    > > ButtonType="LinkButton"
    > > UpdateText="<img src='..\images\update.png' border='0'>"
    > >CancelText="<img src='..\images\Cancel.png' border='0'>" />
    > > <asp:TemplateColumn >
    > > <FooterTemplate>
    > > <asp:LinkButton CommandName="Insert" Text="<img
    > >src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
    > > </FooterTemplate>
    > > <ItemTemplate>
    > > <asp:LinkButton CommandName="Delete" Text="<img
    > >src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > </Columns>
    > ></asp:DataGrid>

    >
    >***************************************************************************

    ************
    > >
    > >I have the DataGrid by doing something like:
    > >
    > > for each oItem as DataListItem in DataList1.Items
    > > Dim oGrid as DataGrid =

    CType(oItem.FindControl("DataGrid1"),DataGrid)
    > >
    > >How would I use oGrid to find and set "lblPositionIDFooter" and
    > >"lblQuestionUniqueFooter"?
    > >
    > >I need this as I need a place to put the PositionID and QuestionUnique as
    > >they are keys I need to use in my Insert statement. I am inserting rows
    > >from the Footer and need to get these variables from some where, so this
    > >seems to be the most logical place to store them.
    > >
    > >Thanks,
    > >
    > >Tom.
    > >

    >
     
    tshad, Nov 3, 2004
    #7
  8. tshad,

    After a week or two of trying to solve a similar issue, I stumbles upon your
    post.

    Alleluia! I believe I am on my way to solving my problem. I'll post back in
    a couple of hours and let you know if this really was it.

    I have a datagrid with 2 nested datagrids. Here is a screenshot.
    http://www.smartbizniz.com/ee/SBS_VarianceNarrative_EE_Sample.pdf

    I am using the footers of the nested datagrids to add new records. It was
    easy for the users to push the Add link to add records one by one. They got
    tired of that and wanted to add new records a page at a time.

    I could loop through the records in the master datagrid and get at the
    nested datagrid but I couldn't figure out how to get the values in the nested
    datagrid's footer. Now I have it:

    Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnTest.Click

    Dim strText As String

    For Each item As DataGridItem In DataGrid1.Items

    Dim dgTemp As DataGrid = CType(item.FindControl("DataGrid_PTD"),
    DataGrid)
    Dim txt As TextBox =
    CType(dgTemp.Controls(0).Controls(1).FindControl("txtPTDsNarrativeAdd"),
    TextBox)
    If txt Is Nothing Then
    strText = ""
    Else
    strText = txt.Text
    End If

    'Now add a new record to the dataset
    Next

    End Sub

    Have you been able to solve your problem?

    "tshad" wrote:

    > "Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    > news:eek:...
    > > Hi tshad:
    > >
    > > You might want to try during the ItemDataBound event instead (check
    > > for e.Item.ItemType == ListItemType.Footer).
    > >
    > > If you need to wait until afterwards, then you can index into the
    > > Controls collection of the grid. (The Items collection might look
    > > tempting at first, but it only contains DataGridItems bound to
    > > records, the header and footer items appear only in the Controls
    > > collection). The footer item should be in the last element of the
    > > Controls array.
    > >
    > > I have some examples about 1/2 through this article:
    > > http://www.odetocode.com/Articles/116.aspx

    >
    > I tried some of what you had and here is what I came up with.
    >
    > The routine where I need to get access to the label in the footer is:
    >
    > **********************************************************************
    > Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
    > if e.CommandName = "Select" then
    > DataList1.SelectedIndex = e.Item.ItemIndex
    > end if
    >
    > Dim oGrid as DataGrid =
    > CType(DataList1.Items(DataList1.SelectedIndex).FindControl("DataGrid1"),Data
    > Grid)
    >
    > Dim lblPositionIDF as Label =
    > oGrid.Controls(0).Controls(0).FindControl("lblPositionIDFooter")
    > **********************************************************************
    >
    > Gives me the following error:
    >
    > Specified argument was out of the range of valid values. Parameter name:
    > index
    >
    > The DataGrid footer section looks like:
    >
    > **********************************************************************
    > <asp:TemplateColumn visible="true">
    > <ItemTemplate>
    > <asp:Label id="lblPositionID" runat="server" Text='<%#
    > DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:Label id="lblPositionIDFooter" runat="server">
    > </asp:Label>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    > **********************************************************************
    >
    > This doesn't seem to be it, unless I am missing something (and I probably
    > am).
    >
    > Thanks,
    >
    > Tom.
    >
    > >
    > > HTH,
    > >
    > > --
    > > Scott
    > > http://www.OdeToCode.com/blogs/scott/
    > >
    > >
    > >
    > >
    > > On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
    > > <> wrote:
    > >
    > > >How do I find (and set) a couple of labels in the Footer after a DataGrid

    > is
    > > >filled?
    > > >
    > > >I have a bunch of DataGrids that get displayed nested inside a DataList.
    > > >
    > > >The datagrid looks like:
    > > >

    > >
    > >***************************************************************************

    > ****
    > > ><asp:DataGrid visible="False"
    > > > border=1
    > > > id="DataGrid1"
    > > > runat="server"
    > > > Width="400px"
    > > > Height="79px"
    > > > AutoGenerateColumns="False"
    > > > GridLines="None"
    > > > ShowFooter="true"
    > > > onItemDataBound="DataGrid1_ItemDataBound"
    > > > OnItemCommand="DataInsert"
    > > > onEditCommand="DataEdit"
    > > > onCancelCommand="DataCancel"
    > > > onUpdateCommand="DataUpdate">
    > > > <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
    > > >BorderColor="White" BackColor="linen"></AlternatingItemStyle>
    > > > <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
    > > > <Columns>
    > > > <asp:TemplateColumn HeaderText="Answer">
    > > > <ItemTemplate>
    > > > <asp:Label id="lblAnswer" runat="server" Text='<%#
    > > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > > </asp:Label>
    > > > </ItemTemplate>
    > > > <FooterTemplate>
    > > > <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
    > > > </FooterTemplate>
    > > > <EditItemTemplate>
    > > > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    > > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > > </asp:textbox>
    > > > </EditItemTemplate>
    > > > </asp:templateColumn>
    > > > <asp:TemplateColumn >
    > > > <ItemTemplate>
    > > > <asp:Label id="lblPositionID" runat="server" Text='<%#
    > > >DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > > > </asp:Label>
    > > > </ItemTemplate>
    > > > <FooterTemplate>
    > > > <asp:Label id="lblPositionIDFooter" runat="server">
    > > > </asp:Label>
    > > > </FooterTemplate>
    > > > </asp:TemplateColumn>
    > > > <asp:TemplateColumn >
    > > > <ItemTemplate>
    > > > <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
    > > >DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    > > > </asp:Label>
    > > > </ItemTemplate>
    > > > <FooterTemplate>
    > > > <asp:Label id="lblQuestionUniqueFooter" runat="server">
    > > > </asp:Label>
    > > > </FooterTemplate>
    > > > </asp:TemplateColumn>
    > > > <asp:BoundColumn DataField="AnswerUnique" visible="false"

    > ReadOnly="true"
    > > >HeaderText="AnswerUnique"></asp:BoundColumn>
    > > > <asp:EditCommandColumn EditText="<img

    > src='..\images\Edit.png'border='0'
    > > >id='textbox1'>" visible="true"
    > > > ButtonType="LinkButton"
    > > > UpdateText="<img src='..\images\update.png' border='0'>"
    > > >CancelText="<img src='..\images\Cancel.png' border='0'>" />
    > > > <asp:TemplateColumn >
    > > > <FooterTemplate>
    > > > <asp:LinkButton CommandName="Insert" Text="<img
    > > >src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
    > > > </FooterTemplate>
    > > > <ItemTemplate>
    > > > <asp:LinkButton CommandName="Delete" Text="<img
    > > >src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
    > > > </ItemTemplate>
    > > > </asp:TemplateColumn>
    > > > </Columns>
    > > ></asp:DataGrid>

    > >
    > >***************************************************************************

    > ************
    > > >
    > > >I have the DataGrid by doing something like:
    > > >
    > > > for each oItem as DataListItem in DataList1.Items
    > > > Dim oGrid as DataGrid =

    > CType(oItem.FindControl("DataGrid1"),DataGrid)
    > > >
    > > >How would I use oGrid to find and set "lblPositionIDFooter" and
    > > >"lblQuestionUniqueFooter"?
    > > >
    > > >I need this as I need a place to put the PositionID and QuestionUnique as
    > > >they are keys I need to use in my Insert statement. I am inserting rows
    > > >from the Footer and need to get these variables from some where, so this
    > > >seems to be the most logical place to store them.
    > > >
    > > >Thanks,
    > > >
    > > >Tom.
    > > >

    > >

    >
    >
    >
     
    =?Utf-8?B?Sm9obiBEZXNhdXRlbHM=?=, Nov 16, 2004
    #8
  9. tshad:

    This was it!

    It took a little while for me to realize that the index for the footer
    control changes depending on how many records are in the datagrid. However,
    in my case it is always the last control.

    Hope you were able to solve your problem.

    Here is my code:

    Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnTest.Click

    Dim strNarrativePTD As String
    Dim strNarrativeYTD As String
    Dim intFooterPTD As Integer
    Dim intFooterYTD As Integer
    Dim intNarrativeType As Int16
    Dim intSortOrder As Integer = 1 'Sort order has not been implemented yet

    For Each item As DataGridItem In DataGrid1.Items

    Dim dgPTD As DataGrid = CType(item.FindControl("DataGrid_PTD"),
    DataGrid)
    Dim dgYTD As DataGrid = CType(item.FindControl("DataGrid_YTD"),
    DataGrid)

    'The Footer section is the last control in the nested datagrid. We
    will use this index later.
    intFooterPTD = dgPTD.Controls(0).Controls.Count - 1
    intFooterYTD = dgYTD.Controls(0).Controls.Count - 1

    'First check the PTD Comments
    Dim txtPTD As TextBox =
    CType(dgPTD.Controls(0).Controls(intFooterPTD).FindControl("txtPTDsNarrativeAdd"), TextBox)
    Dim lblPTD As Label =
    CType(dgPTD.Controls(0).Controls(intFooterPTD).FindControl("lblhAcctPTDAdd"),
    Label)
    If txtPTD Is Nothing Then
    strNarrativePTD = ""
    Else
    strNarrativePTD = txtPTD.Text
    strHAcct = lblPTD.Text
    intNarrativeType = 1
    End If

    'If there is something in the textbox, add the record.
    If Len(strNarrativePTD) > 0 Then
    NarrativesAdd(intNarrativeType, strNarrativePTD, intSortOrder)
    End If

    'Second check the YTD Comments
    Dim txtYTD As TextBox =
    CType(dgYTD.Controls(0).Controls(intFooterYTD).FindControl("txtYTDsNarrativeAdd"), TextBox)
    Dim lblYTD As Label =
    CType(dgYTD.Controls(0).Controls(intFooterYTD).FindControl("lblhAcctYTDAdd"),
    Label)
    If txtYTD Is Nothing Then
    strNarrativeYTD = ""
    Else
    strNarrativeYTD = txtYTD.Text
    strHAcct = lblYTD.Text
    intNarrativeType = 12
    End If

    'If there is something in the textbox, add the record.
    If Len(strNarrativeYTD) > 0 Then
    NarrativesAdd(intNarrativeType, strNarrativeYTD, intSortOrder)
    End If

    Next

    LoadGrid()

    End Sub

    "tshad" wrote:

    > "Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    > news:eek:...
    > > Hi tshad:
    > >
    > > You might want to try during the ItemDataBound event instead (check
    > > for e.Item.ItemType == ListItemType.Footer).
    > >
    > > If you need to wait until afterwards, then you can index into the
    > > Controls collection of the grid. (The Items collection might look
    > > tempting at first, but it only contains DataGridItems bound to
    > > records, the header and footer items appear only in the Controls
    > > collection). The footer item should be in the last element of the
    > > Controls array.
    > >
    > > I have some examples about 1/2 through this article:
    > > http://www.odetocode.com/Articles/116.aspx

    >
    > I tried some of what you had and here is what I came up with.
    >
    > The routine where I need to get access to the label in the footer is:
    >
    > **********************************************************************
    > Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
    > if e.CommandName = "Select" then
    > DataList1.SelectedIndex = e.Item.ItemIndex
    > end if
    >
    > Dim oGrid as DataGrid =
    > CType(DataList1.Items(DataList1.SelectedIndex).FindControl("DataGrid1"),Data
    > Grid)
    >
    > Dim lblPositionIDF as Label =
    > oGrid.Controls(0).Controls(0).FindControl("lblPositionIDFooter")
    > **********************************************************************
    >
    > Gives me the following error:
    >
    > Specified argument was out of the range of valid values. Parameter name:
    > index
    >
    > The DataGrid footer section looks like:
    >
    > **********************************************************************
    > <asp:TemplateColumn visible="true">
    > <ItemTemplate>
    > <asp:Label id="lblPositionID" runat="server" Text='<%#
    > DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:Label id="lblPositionIDFooter" runat="server">
    > </asp:Label>
    > </FooterTemplate>
    > </asp:TemplateColumn>
    > **********************************************************************
    >
    > This doesn't seem to be it, unless I am missing something (and I probably
    > am).
    >
    > Thanks,
    >
    > Tom.
    >
    > >
    > > HTH,
    > >
    > > --
    > > Scott
    > > http://www.OdeToCode.com/blogs/scott/
    > >
    > >
    > >
    > >
    > > On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
    > > <> wrote:
    > >
    > > >How do I find (and set) a couple of labels in the Footer after a DataGrid

    > is
    > > >filled?
    > > >
    > > >I have a bunch of DataGrids that get displayed nested inside a DataList.
    > > >
    > > >The datagrid looks like:
    > > >

    > >
    > >***************************************************************************

    > ****
    > > ><asp:DataGrid visible="False"
    > > > border=1
    > > > id="DataGrid1"
    > > > runat="server"
    > > > Width="400px"
    > > > Height="79px"
    > > > AutoGenerateColumns="False"
    > > > GridLines="None"
    > > > ShowFooter="true"
    > > > onItemDataBound="DataGrid1_ItemDataBound"
    > > > OnItemCommand="DataInsert"
    > > > onEditCommand="DataEdit"
    > > > onCancelCommand="DataCancel"
    > > > onUpdateCommand="DataUpdate">
    > > > <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
    > > >BorderColor="White" BackColor="linen"></AlternatingItemStyle>
    > > > <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
    > > > <Columns>
    > > > <asp:TemplateColumn HeaderText="Answer">
    > > > <ItemTemplate>
    > > > <asp:Label id="lblAnswer" runat="server" Text='<%#
    > > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > > </asp:Label>
    > > > </ItemTemplate>
    > > > <FooterTemplate>
    > > > <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
    > > > </FooterTemplate>
    > > > <EditItemTemplate>
    > > > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    > > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    > > > </asp:textbox>
    > > > </EditItemTemplate>
    > > > </asp:templateColumn>
    > > > <asp:TemplateColumn >
    > > > <ItemTemplate>
    > > > <asp:Label id="lblPositionID" runat="server" Text='<%#
    > > >DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    > > > </asp:Label>
    > > > </ItemTemplate>
    > > > <FooterTemplate>
    > > > <asp:Label id="lblPositionIDFooter" runat="server">
    > > > </asp:Label>
    > > > </FooterTemplate>
    > > > </asp:TemplateColumn>
    > > > <asp:TemplateColumn >
    > > > <ItemTemplate>
    > > > <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
    > > >DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    > > > </asp:Label>
    > > > </ItemTemplate>
    > > > <FooterTemplate>
    > > > <asp:Label id="lblQuestionUniqueFooter" runat="server">
    > > > </asp:Label>
    > > > </FooterTemplate>
    > > > </asp:TemplateColumn>
    > > > <asp:BoundColumn DataField="AnswerUnique" visible="false"

    > ReadOnly="true"
    > > >HeaderText="AnswerUnique"></asp:BoundColumn>
    > > > <asp:EditCommandColumn EditText="<img

    > src='..\images\Edit.png'border='0'
    > > >id='textbox1'>" visible="true"
    > > > ButtonType="LinkButton"
    > > > UpdateText="<img src='..\images\update.png' border='0'>"
    > > >CancelText="<img src='..\images\Cancel.png' border='0'>" />
    > > > <asp:TemplateColumn >
    > > > <FooterTemplate>
    > > > <asp:LinkButton CommandName="Insert" Text="<img
    > > >src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
    > > > </FooterTemplate>
    > > > <ItemTemplate>
    > > > <asp:LinkButton CommandName="Delete" Text="<img
    > > >src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
    > > > </ItemTemplate>
    > > > </asp:TemplateColumn>
    > > > </Columns>
    > > ></asp:DataGrid>

    > >
    > >***************************************************************************

    > ************
    > > >
    > > >I have the DataGrid by doing something like:
    > > >
    > > > for each oItem as DataListItem in DataList1.Items
    > > > Dim oGrid as DataGrid =

    > CType(oItem.FindControl("DataGrid1"),DataGrid)
    > > >
    > > >How would I use oGrid to find and set "lblPositionIDFooter" and
    > > >"lblQuestionUniqueFooter"?
    > > >
    > > >I need this as I need a place to put the PositionID and QuestionUnique as
    > > >they are keys I need to use in my Insert statement. I am inserting rows
    > > >from the Footer and need to get these variables from some where, so this
    > > >seems to be the most logical place to store them.
    > > >
    > > >Thanks,
    > > >
    > > >Tom.
    > > >

    > >

    >
    >
    >
     
    =?Utf-8?B?Sm9obiBEZXNhdXRlbHM=?=, Nov 16, 2004
    #9
  10. tshad

    tshad Guest

    "John Desautels" <John > wrote in message
    news:...
    > tshad:
    >
    > This was it!
    >
    > It took a little while for me to realize that the index for the footer
    > control changes depending on how many records are in the datagrid.
    > However,
    > in my case it is always the last control.
    >
    > Hope you were able to solve your problem.


    Actually,

    I did. But not the way I wanted to.

    The problem was I have multiple grids inside of a datalist. Each grid was a
    different set up records differentiated by a unique number. My problem is
    finding out what the unique number was.

    I figured I would just look through the datalist until I find the datagrid
    that matched the name of the one I was using. I know that the table ID's
    would be different when the page was rendered. What I didn't realize that
    in ASP, before it is rendered, all the ID's are identical. So that didn't
    work.

    What I ended up doing was puting the unique number in a hidden column on the
    footer as the table was being populated. Then when I did the insert I would
    already be pointing at the Footer and I could get the data easily at that
    point.

    What I haven't been able to do was figure out how to find out which Datalist
    row (the parent) is equated with the Datagrid I am working with. I assume I
    will have the same problem - same name.

    Thanks,

    Tom.
    >
    > Here is my code:
    >
    > Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles btnTest.Click
    >
    > Dim strNarrativePTD As String
    > Dim strNarrativeYTD As String
    > Dim intFooterPTD As Integer
    > Dim intFooterYTD As Integer
    > Dim intNarrativeType As Int16
    > Dim intSortOrder As Integer = 1 'Sort order has not been implemented
    > yet
    >
    > For Each item As DataGridItem In DataGrid1.Items
    >
    > Dim dgPTD As DataGrid = CType(item.FindControl("DataGrid_PTD"),
    > DataGrid)
    > Dim dgYTD As DataGrid = CType(item.FindControl("DataGrid_YTD"),
    > DataGrid)
    >
    > 'The Footer section is the last control in the nested datagrid. We
    > will use this index later.
    > intFooterPTD = dgPTD.Controls(0).Controls.Count - 1
    > intFooterYTD = dgYTD.Controls(0).Controls.Count - 1
    >
    > 'First check the PTD Comments
    > Dim txtPTD As TextBox =
    > CType(dgPTD.Controls(0).Controls(intFooterPTD).FindControl("txtPTDsNarrativeAdd"),
    > TextBox)
    > Dim lblPTD As Label =
    > CType(dgPTD.Controls(0).Controls(intFooterPTD).FindControl("lblhAcctPTDAdd"),
    > Label)
    > If txtPTD Is Nothing Then
    > strNarrativePTD = ""
    > Else
    > strNarrativePTD = txtPTD.Text
    > strHAcct = lblPTD.Text
    > intNarrativeType = 1
    > End If
    >
    > 'If there is something in the textbox, add the record.
    > If Len(strNarrativePTD) > 0 Then
    > NarrativesAdd(intNarrativeType, strNarrativePTD, intSortOrder)
    > End If
    >
    > 'Second check the YTD Comments
    > Dim txtYTD As TextBox =
    > CType(dgYTD.Controls(0).Controls(intFooterYTD).FindControl("txtYTDsNarrativeAdd"),
    > TextBox)
    > Dim lblYTD As Label =
    > CType(dgYTD.Controls(0).Controls(intFooterYTD).FindControl("lblhAcctYTDAdd"),
    > Label)
    > If txtYTD Is Nothing Then
    > strNarrativeYTD = ""
    > Else
    > strNarrativeYTD = txtYTD.Text
    > strHAcct = lblYTD.Text
    > intNarrativeType = 12
    > End If
    >
    > 'If there is something in the textbox, add the record.
    > If Len(strNarrativeYTD) > 0 Then
    > NarrativesAdd(intNarrativeType, strNarrativeYTD, intSortOrder)
    > End If
    >
    > Next
    >
    > LoadGrid()
    >
    > End Sub
    >
    > "tshad" wrote:
    >
    >> "Scott Allen" <bitmask@[nospam].fred.net> wrote in message
    >> news:eek:...
    >> > Hi tshad:
    >> >
    >> > You might want to try during the ItemDataBound event instead (check
    >> > for e.Item.ItemType == ListItemType.Footer).
    >> >
    >> > If you need to wait until afterwards, then you can index into the
    >> > Controls collection of the grid. (The Items collection might look
    >> > tempting at first, but it only contains DataGridItems bound to
    >> > records, the header and footer items appear only in the Controls
    >> > collection). The footer item should be in the last element of the
    >> > Controls array.
    >> >
    >> > I have some examples about 1/2 through this article:
    >> > http://www.odetocode.com/Articles/116.aspx

    >>
    >> I tried some of what you had and here is what I came up with.
    >>
    >> The routine where I need to get access to the label in the footer is:
    >>
    >> **********************************************************************
    >> Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
    >> if e.CommandName = "Select" then
    >> DataList1.SelectedIndex = e.Item.ItemIndex
    >> end if
    >>
    >> Dim oGrid as DataGrid =
    >> CType(DataList1.Items(DataList1.SelectedIndex).FindControl("DataGrid1"),Data
    >> Grid)
    >>
    >> Dim lblPositionIDF as Label =
    >> oGrid.Controls(0).Controls(0).FindControl("lblPositionIDFooter")
    >> **********************************************************************
    >>
    >> Gives me the following error:
    >>
    >> Specified argument was out of the range of valid values. Parameter name:
    >> index
    >>
    >> The DataGrid footer section looks like:
    >>
    >> **********************************************************************
    >> <asp:TemplateColumn visible="true">
    >> <ItemTemplate>
    >> <asp:Label id="lblPositionID" runat="server" Text='<%#
    >> DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    >> </asp:Label>
    >> </ItemTemplate>
    >> <FooterTemplate>
    >> <asp:Label id="lblPositionIDFooter" runat="server">
    >> </asp:Label>
    >> </FooterTemplate>
    >> </asp:TemplateColumn>
    >> **********************************************************************
    >>
    >> This doesn't seem to be it, unless I am missing something (and I probably
    >> am).
    >>
    >> Thanks,
    >>
    >> Tom.
    >>
    >> >
    >> > HTH,
    >> >
    >> > --
    >> > Scott
    >> > http://www.OdeToCode.com/blogs/scott/
    >> >
    >> >
    >> >
    >> >
    >> > On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
    >> > <> wrote:
    >> >
    >> > >How do I find (and set) a couple of labels in the Footer after a
    >> > >DataGrid

    >> is
    >> > >filled?
    >> > >
    >> > >I have a bunch of DataGrids that get displayed nested inside a
    >> > >DataList.
    >> > >
    >> > >The datagrid looks like:
    >> > >
    >> >
    >> >***************************************************************************

    >> ****
    >> > ><asp:DataGrid visible="False"
    >> > > border=1
    >> > > id="DataGrid1"
    >> > > runat="server"
    >> > > Width="400px"
    >> > > Height="79px"
    >> > > AutoGenerateColumns="False"
    >> > > GridLines="None"
    >> > > ShowFooter="true"
    >> > > onItemDataBound="DataGrid1_ItemDataBound"
    >> > > OnItemCommand="DataInsert"
    >> > > onEditCommand="DataEdit"
    >> > > onCancelCommand="DataCancel"
    >> > > onUpdateCommand="DataUpdate">
    >> > > <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
    >> > >BorderColor="White" BackColor="linen"></AlternatingItemStyle>
    >> > > <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
    >> > > <Columns>
    >> > > <asp:TemplateColumn HeaderText="Answer">
    >> > > <ItemTemplate>
    >> > > <asp:Label id="lblAnswer" runat="server" Text='<%#
    >> > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    >> > > </asp:Label>
    >> > > </ItemTemplate>
    >> > > <FooterTemplate>
    >> > > <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
    >> > > </FooterTemplate>
    >> > > <EditItemTemplate>
    >> > > <asp:textbox id="txtAnswer" runat="server" Text='<%#
    >> > >DataBinder.Eval(Container, "DataItem.Answer") %>'>
    >> > > </asp:textbox>
    >> > > </EditItemTemplate>
    >> > > </asp:templateColumn>
    >> > > <asp:TemplateColumn >
    >> > > <ItemTemplate>
    >> > > <asp:Label id="lblPositionID" runat="server" Text='<%#
    >> > >DataBinder.Eval(Container, "DataItem.PositionID") %>'>
    >> > > </asp:Label>
    >> > > </ItemTemplate>
    >> > > <FooterTemplate>
    >> > > <asp:Label id="lblPositionIDFooter" runat="server">
    >> > > </asp:Label>
    >> > > </FooterTemplate>
    >> > > </asp:TemplateColumn>
    >> > > <asp:TemplateColumn >
    >> > > <ItemTemplate>
    >> > > <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
    >> > >DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
    >> > > </asp:Label>
    >> > > </ItemTemplate>
    >> > > <FooterTemplate>
    >> > > <asp:Label id="lblQuestionUniqueFooter" runat="server">
    >> > > </asp:Label>
    >> > > </FooterTemplate>
    >> > > </asp:TemplateColumn>
    >> > > <asp:BoundColumn DataField="AnswerUnique" visible="false"

    >> ReadOnly="true"
    >> > >HeaderText="AnswerUnique"></asp:BoundColumn>
    >> > > <asp:EditCommandColumn EditText="<img

    >> src='..\images\Edit.png'border='0'
    >> > >id='textbox1'>" visible="true"
    >> > > ButtonType="LinkButton"
    >> > > UpdateText="<img src='..\images\update.png' border='0'>"
    >> > >CancelText="<img src='..\images\Cancel.png' border='0'>" />
    >> > > <asp:TemplateColumn >
    >> > > <FooterTemplate>
    >> > > <asp:LinkButton CommandName="Insert" Text="<img
    >> > >src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
    >> > > </FooterTemplate>
    >> > > <ItemTemplate>
    >> > > <asp:LinkButton CommandName="Delete" Text="<img
    >> > >src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
    >> > > </ItemTemplate>
    >> > > </asp:TemplateColumn>
    >> > > </Columns>
    >> > ></asp:DataGrid>
    >> >
    >> >***************************************************************************

    >> ************
    >> > >
    >> > >I have the DataGrid by doing something like:
    >> > >
    >> > > for each oItem as DataListItem in DataList1.Items
    >> > > Dim oGrid as DataGrid =

    >> CType(oItem.FindControl("DataGrid1"),DataGrid)
    >> > >
    >> > >How would I use oGrid to find and set "lblPositionIDFooter" and
    >> > >"lblQuestionUniqueFooter"?
    >> > >
    >> > >I need this as I need a place to put the PositionID and QuestionUnique
    >> > >as
    >> > >they are keys I need to use in my Insert statement. I am inserting
    >> > >rows
    >> > >from the Footer and need to get these variables from some where, so
    >> > >this
    >> > >seems to be the most logical place to store them.
    >> > >
    >> > >Thanks,
    >> > >
    >> > >Tom.
    >> > >
    >> >

    >>
    >>
    >>
     
    tshad, Nov 17, 2004
    #10
    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. Sue
    Replies:
    2
    Views:
    389
  2. =?Utf-8?B?Q2hyaXMgRmluaw==?=

    Find Button Control in DataList Footer

    =?Utf-8?B?Q2hyaXMgRmluaw==?=, Sep 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,429
    Hermit Dave
    Sep 27, 2004
  3. John
    Replies:
    2
    Views:
    456
  4. =?Utf-8?B?SmltIEhlYXZleQ==?=

    Find All Labels On Form

    =?Utf-8?B?SmltIEhlYXZleQ==?=, Aug 1, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    446
  5. Henrik
    Replies:
    1
    Views:
    427
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
Loading...

Share This Page