View Single Post
  #1 (permalink)  
Old August 25th, 2009, 08:51 PM
phuc2583 phuc2583 is offline
Authorized User
 
Join Date: Dec 2007
Location: , , Vietnam.
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts
Post Do not get value from GridViewRow

Hello everybody

I have tried my best to get value from the Grid view but not successful.
Here is the my code. when i debug ,it ignore "For Each" statement.
Can you give me your ideal about the code behind below.
Function Booking_DetailAdd2() As String
Dim kq As String = ""
For Each gvr As GridViewRow In Me.gvRoomType.Rows
Dim cb As CheckBox = CType(gvr.FindControl("cbkRoomName"), CheckBox)
Dim cbSingle As CheckBox = CType(gvr.FindControl("cbkSingleP"), CheckBox)
Dim cbDouble As CheckBox = CType(gvr.FindControl("cbkDoubleP"), CheckBox)
Dim cbTriple As CheckBox = CType(gvr.FindControl("cbkTripleP"), CheckBox)
If cb.Checked Then
kq = "<hr><br>Room Type : " & cb.Text & _
"<br>Quantity Room:" & CType(gvr.FindControl("cbQuantityRoom"), DropDownList).SelectedValue
If cbSingle.Checked Then
kq &= "<br> Single Room : $" & CType(gvr.FindControl("cbkSingleP"), CheckBox).Text
End If
If cbDouble.Checked Then
kq &= "<br> Double Room : $" & CType(gvr.FindControl("cbkDoubleP"), CheckBox).Text
End If
If cbTriple.Checked Then
kq &= "<br> Triple Room : $" & CType(gvr.FindControl("cbkTripleP"), CheckBox).Text
End If
End If
Next
Return kq
End Function
-----------------------
HTML
<asp:GridView ID="gvRoomType" runat="server" AutoGenerateColumns="False" CellPadding="5"
ForeColor="#333333" GridLines="None" HorizontalAlign="Center" Width="100%" DataKeyNames="RoomTypeID">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="Room Type">
<ItemStyle Width="240px" />
<ItemTemplate>
<asp:CheckBox ID="cbkRoomName" runat="server" Font-Bold="True" ForeColor="#400000"
Text='<%# Bind("RoomTypeName") %>' /><br />

</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Height="25px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity Room">
<ItemStyle Width="100px" Wrap="False" HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="cbQuantityRoom" runat="server" Width="40px">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Single">
<EditItemTemplate>
&nbsp;
</EditItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="100px" />
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:CheckBox ID="cbkSingleP" runat="server" Font-Bold="False" ForeColor="#000040"
Text='<%# Bind("SinglePrice") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Double">
<ItemStyle HorizontalAlign="Left" Width="100px" Wrap="False" />
<HeaderStyle HorizontalAlign="Center" Width="50px" />
<ItemTemplate>
<asp:CheckBox ID="cbkDoubleP" runat="server" Font-Bold="False" ForeColor="#000040"
Text='<%# Bind("DoublePrice") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Triple">
<ItemStyle HorizontalAlign="Left" Width="100px" />
<HeaderStyle HorizontalAlign="Center" Width="50px" />
<ItemTemplate>
<asp:CheckBox ID="cbkTripleP" runat="server" Font-Bold="False" ForeColor="#000040"
Text='<%# Bind("TriplePrice") %>' />
<asp:TextBox ID="txtRoomRequest" runat="server" Visible="False"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" Font-Bold="True" />
<PagerStyle BackColor="#99CCFF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#99CCFF" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
</asp:GridView>

I think it is a mistake on that
So, you can help me find out the solve
Best regards,
Phuc Hoang

Last edited by phuc2583; August 25th, 2009 at 09:21 PM.. Reason: Lack of information