Connecting Tech Pros Worldwide Forums | Help | Site Map

Unable to find control in Gridview

parshupooja's Avatar
Familiar Sight
 
Join Date: Jun 2007
Posts: 159
#1: Jun 28 '09
Hey All,
I have where I want to do some manipulations and show in other column but unable to find their values in RowDatabound event even though I have two records in gridview
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" ShowFooter="True" AutoGenerateColumns="false" Width="700px">
  2.         <Columns>
  3.                      <asp:TemplateField HeaderText="Qty">
  4.                         <EditItemTemplate>
  5.                             <asp:TextBox ID="TextBoxCode" runat="server" Width="20pt" Text='<%# Bind("Qty") %>'/>
  6.                         </EditItemTemplate>
  7.                         <ItemTemplate>
  8.                             <asp:Label ID="lblQty" runat="server" Text='<%# Eval("Qty") %>' />
  9.                         </ItemTemplate>
  10.                         <FooterTemplate>
  11.                             <asp:TextBox ID="TextQTY" runat="server" Width="20pt" Text='<%# Bind("Qty") %>'/>
  12.                         </FooterTemplate>
  13.                     </asp:TemplateField>                                
  14.                      <asp:TemplateField HeaderText="Unit Price">
  15.                       <EditItemTemplate>                            
  16.                         </EditItemTemplate>
  17.                         <ItemTemplate>
  18.                             <asp:Label ID="lblUnitCost" runat="server" Text='<%# Eval("UnitCost") %>' />
  19.                         </ItemTemplate>
  20.                         <FooterTemplate>
  21.                             <asp:Label ID="lblfooterUnitCost" runat="server" Text='<%# Eval("UnitCost") %>'/>
  22.                         </FooterTemplate>
  23.                     </asp:TemplateField>
  24.  <asp:TemplateField HeaderText="Line Total">
  25.                       <EditItemTemplate>
  26.  
  27.                         </EditItemTemplate>
  28.                         <ItemTemplate>
  29.                             <asp:Label ID="lbllinettl" runat="server" Text="" />
  30.                         </ItemTemplate>
  31.                         <FooterTemplate>
  32.                             <asp:Label ID="lblfooterLinePrice" runat="server" Text=""/>
  33.                         </FooterTemplate>
  34.                     </asp:TemplateField>
  35.                 </Columns>
  36.         </asp:GridView>     
  37.  
I want to do some calculations in gridview that is lbllinettl = lblUnitCost * lblQty
Here is my RowDAtaBound Event. I don't know why Qty is coming up blank

Expand|Select|Wrap|Line Numbers
  1. Protected Sub GridView1_RowDataBound(ByVal sender As Object,        If (e.Row.RowType = DataControlRowType.DataRow) Then ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
  2.  
  3.             Dim Qty As String
  4.             Qty = CType(e.Row.FindControl("lblQty"), Label).Text
  5.         End If
  6. end Sub
Thanks, Help appreciated

Newbie
 
Join Date: Jun 2009
Posts: 2
#2: Jun 28 '09

re: Unable to find control in Gridview


hi

Try using
Expand|Select|Wrap|Line Numbers
  1. ((Label)GridView1.Rows[0].Cells[0].Controls[5]).text
Hope it helps

Nitin
<link removed by moderator>
Reply