template columns and bound columns in gridview

Discussion in 'ASP .Net Web Controls' started by Vinki, Apr 25, 2007.

  1. Vinki

    Vinki Guest

    Hello Everyone,

    In my gridview, I changed some of the bound columns to template columns, I
    noticed that the template column is not recognized inside the RowDataBound
    event method. The reason I changed the bound columns to template columns so
    that I can add the total column in the footer. I guess I cannot do that with
    bound columns.
    If I do e.Row.Cells[5].Text then 5th column is not recognixed inside the
    Rowdatabound event, but If i do e.Row.Cells[4].Text then it is recognized.
    Please let me know what am I doing wrong.

    <asp:GridView ID="dgAgentActivity" runat="server"
    AutoGenerateColumns="false" CellPadding="0" CellSpacing="1"
    BackColor="AliceBlue" OnRowDataBound="dgAgentActivity_RowDataBound"
    OnRowCreated="dgAgentActivity_RowCreated" ShowFooter="true">
    <Columns>

    <asp:BoundField HeaderText ="Time" DataField="SwitchTime" />
    <asp:BoundField HeaderText ="State1" DataField="TerminalState" />
    <asp:BoundField HeaderText ="State2" DataField="AgentState" />
    <asp:BoundField HeaderText ="Que" DataField="Queue" />
    <asp:BoundField HeaderText ="calculated Time"
    DataField="calculated Time"/>


    <asp:templatefield headertext="LogOut" >

    <itemtemplate>
    <%#Eval("LogOut", "{0:c}")%>
    </itemtemplate>
    <footertemplate>
    <asp:label id="TotalTime" runat="server"/>
    </footertemplate>
    </asp:templatefield>
    <asp:BoundField HeaderText ="test1 DataField="Not Ready" />


    </Columns>


    </asp:GridView>


    protected void dgAgentActivity_RowDataBound(object sender,
    GridViewRowEventArgs e)
    {

    }

    Thanks.
    Vinki, Apr 25, 2007
    #1
    1. Advertising

  2. Vinki

    Manish Bafna Guest

    Hi,
    What i am going to tell is very basic but hoping that might help you.
    You see it is zero based index.That is e.Row.Cells[4].Text will return
    content of 5th column and .Row.Cells[0].Text will return content of 1st column
    Hope this helps
    --
    If my answer helped you,then please do press Yes below.
    Thanks and Regards.
    Manish Bafna.
    MCP and MCTS.



    "Vinki" wrote:

    > Hello Everyone,
    >
    > In my gridview, I changed some of the bound columns to template columns, I
    > noticed that the template column is not recognized inside the RowDataBound
    > event method. The reason I changed the bound columns to template columns so
    > that I can add the total column in the footer. I guess I cannot do that with
    > bound columns.
    > If I do e.Row.Cells[5].Text then 5th column is not recognixed inside the
    > Rowdatabound event, but If i do e.Row.Cells[4].Text then it is recognized.
    > Please let me know what am I doing wrong.
    >
    > <asp:GridView ID="dgAgentActivity" runat="server"
    > AutoGenerateColumns="false" CellPadding="0" CellSpacing="1"
    > BackColor="AliceBlue" OnRowDataBound="dgAgentActivity_RowDataBound"
    > OnRowCreated="dgAgentActivity_RowCreated" ShowFooter="true">
    > <Columns>
    >
    > <asp:BoundField HeaderText ="Time" DataField="SwitchTime" />
    > <asp:BoundField HeaderText ="State1" DataField="TerminalState" />
    > <asp:BoundField HeaderText ="State2" DataField="AgentState" />
    > <asp:BoundField HeaderText ="Que" DataField="Queue" />
    > <asp:BoundField HeaderText ="calculated Time"
    > DataField="calculated Time"/>
    >
    >
    > <asp:templatefield headertext="LogOut" >
    >
    > <itemtemplate>
    > <%#Eval("LogOut", "{0:c}")%>
    > </itemtemplate>
    > <footertemplate>
    > <asp:label id="TotalTime" runat="server"/>
    > </footertemplate>
    > </asp:templatefield>
    > <asp:BoundField HeaderText ="test1 DataField="Not Ready" />
    >
    >
    > </Columns>
    >
    >
    > </asp:GridView>
    >
    >
    > protected void dgAgentActivity_RowDataBound(object sender,
    > GridViewRowEventArgs e)
    > {
    >
    > }
    >
    > Thanks.
    Manish Bafna, Apr 25, 2007
    #2
    1. Advertising

  3. Vinki

    Vinki Guest

    Hi Manish,

    Thanks for responding. I already know about zero based index. I think
    template columns use differnt command to access the cells than bound columns.

    "Manish Bafna" wrote:

    > Hi,
    > What i am going to tell is very basic but hoping that might help you.
    > You see it is zero based index.That is e.Row.Cells[4].Text will return
    > content of 5th column and .Row.Cells[0].Text will return content of 1st column
    > Hope this helps
    > --
    > If my answer helped you,then please do press Yes below.
    > Thanks and Regards.
    > Manish Bafna.
    > MCP and MCTS.
    >
    >
    >
    > "Vinki" wrote:
    >
    > > Hello Everyone,
    > >
    > > In my gridview, I changed some of the bound columns to template columns, I
    > > noticed that the template column is not recognized inside the RowDataBound
    > > event method. The reason I changed the bound columns to template columns so
    > > that I can add the total column in the footer. I guess I cannot do that with
    > > bound columns.
    > > If I do e.Row.Cells[5].Text then 5th column is not recognixed inside the
    > > Rowdatabound event, but If i do e.Row.Cells[4].Text then it is recognized.
    > > Please let me know what am I doing wrong.
    > >
    > > <asp:GridView ID="dgAgentActivity" runat="server"
    > > AutoGenerateColumns="false" CellPadding="0" CellSpacing="1"
    > > BackColor="AliceBlue" OnRowDataBound="dgAgentActivity_RowDataBound"
    > > OnRowCreated="dgAgentActivity_RowCreated" ShowFooter="true">
    > > <Columns>
    > >
    > > <asp:BoundField HeaderText ="Time" DataField="SwitchTime" />
    > > <asp:BoundField HeaderText ="State1" DataField="TerminalState" />
    > > <asp:BoundField HeaderText ="State2" DataField="AgentState" />
    > > <asp:BoundField HeaderText ="Que" DataField="Queue" />
    > > <asp:BoundField HeaderText ="calculated Time"
    > > DataField="calculated Time"/>
    > >
    > >
    > > <asp:templatefield headertext="LogOut" >
    > >
    > > <itemtemplate>
    > > <%#Eval("LogOut", "{0:c}")%>
    > > </itemtemplate>
    > > <footertemplate>
    > > <asp:label id="TotalTime" runat="server"/>
    > > </footertemplate>
    > > </asp:templatefield>
    > > <asp:BoundField HeaderText ="test1 DataField="Not Ready" />
    > >
    > >
    > > </Columns>
    > >
    > >
    > > </asp:GridView>
    > >
    > >
    > > protected void dgAgentActivity_RowDataBound(object sender,
    > > GridViewRowEventArgs e)
    > > {
    > >
    > > }
    > >
    > > Thanks.
    Vinki, Apr 25, 2007
    #3
    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. =?Utf-8?B?RGF2aWQ=?=

    Help a newbie... (DataGrid bound & template columns)

    =?Utf-8?B?RGF2aWQ=?=, Feb 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    406
    Vadivel Kumar
    Feb 10, 2005
  2. keithb
    Replies:
    1
    Views:
    2,715
    Teemu Keiski
    Apr 8, 2006
  3. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,215
    thushara wijeratna
    Oct 7, 2008
  4. Rhiner Dan
    Replies:
    1
    Views:
    738
    Mike Wahler
    Mar 27, 2005
  5. Replies:
    1
    Views:
    477
    Vadivel Kumar
    Jun 27, 2006
Loading...

Share This Page