Multipule information and Pics in multipule gridviews in ASP.NET using VB - sql

I am trying to build a website and am running into a little trouble. My coding knowledge and savvy are armature at best,if you know a better way to do this than please by all means let me know.
On my Featured Bar page I have two gridviews set up. gvPicsRandomBar(For pictures only) and GVRandomBars(For Information only). Each has their own SQLDataSource. I have it set up to where GVRandomBars selects a "random" bar through the SQL TOP command. What I'm trying to do is get the gvPicsRandomBar to display a picture of the same "random" bar that is selected by GVRandomBars. Both gridviews are querying from the same table but with different SELECT statements as each gridview is concerned with different items in the same table row.
I thought I had somewhat accomplished this by reading the primary key from the GVRandomBars and placing that value in a Label(lblRandomBar) that I use as a control for gvPicsRandomBar to match up the correct pic to display in it's own gridview as they both query the same database, but I was wrong. Whenever I startup my website I get this error "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index". I'm just not sure where to place this code i.e. (Event) lblRandomBar.Text = GVRandomBars.DataKeys(0).Value.ToString() so that I will not get the above error.
Seperate problems if by miracle I get it to work
One problem I have is that it appears that the value of the primary key is not passed on to lblRandomBar.text. I assume this is because I do not know where to correctly place the code lblRandomBar.Text = GVRandomBars.DataKeys(0).Value.ToString()The other problem I do have when I sometimes get it to work is that the picture displayed in gvPicsRandomBar is one step behind from when I click the search button. Example, I click search for city "Austin" in my dropdown list which could potentially give me a primary key value of 45. The picture for that primary key is not displayed until I click search for another city in the dropdown list and the page posts back to the server.
The value of the primary key is in lblRandomBar.text for the current bar displayed in the GVRandomBars but the picture of the bar associated with that recored does not appear in the gvPicsRandomBar until the search button is clicked and another "random" bar is displayed in the GVRandomBars. So I am looking at a picture in gvPicsRandomBar from the last bar that was brought up in GVRandomBars while another bars information is currently displayed in GVRadnomBars.
I am looking to have the same bar information and bar picture in both gridviews at the same time, and not one step behind like I have currently with the picture in gvPicsRandomBar. Any help would be greatly appreciated. Thanks.
ASP.NET HTML
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Random Bar.aspx.vb" Inherits="RGVHappyHour.Featured_Bar" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<center><h2>Random Bar</h2></center>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<p>
<asp:GridView ID="gvPicsRandomBar" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Number,Bar Name,Image" DataSourceID="SqlDataSourceRandomBarPics" ForeColor="#333333" GridLines="None" HorizontalAlign="Center" Width="548px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:ImageField DataImageUrlField="Image" HeaderText="Image" NullDisplayText="No Picture">
</asp:ImageField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceRandomBarPics" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringBars %>" SelectCommand="SELECT * FROM [Bars] WHERE ([Number] = #Number)">
<SelectParameters>
<asp:ControlParameter ControlID="lblRandomBar" Name="Number" PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</p>
<p>
<asp:GridView ID="GVRandomBars" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceRandomBar" Width="548px" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" DataKeyNames="Number" SelectedIndex="0">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Bar_Name" HeaderText="Bar Name" SortExpression="Bar_Name" />
<asp:BoundField DataField="Addresss" HeaderText="Addresss" SortExpression="Addresss" />
<asp:BoundField DataField="Phone_Number" HeaderText="Phone Number" SortExpression="Phone_Number" />
<asp:BoundField DataField="Days" HeaderText="Days" SortExpression="Days" />
<asp:BoundField DataField="Happy_Hour" HeaderText="Happy Hour" SortExpression="Happy_Hour" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle ForeColor="#333333" BackColor="#F7F6F3" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceRandomBar" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringBars %>" SelectCommand="SELECT TOP (1) [Number], [Bar Name] AS Bar_Name, Addresss, [Phone Number] AS Phone_Number, Days, [Happy Hour] AS Happy_Hour, [Image] AS Image FROM Bars WHERE (City = #City) ORDER BY NEWID()">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCity" Name="City" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<p>
<table class="style1" style="width: 100%">
<tr>
<td style="width: 220px; text-align: right;" class="style2">
<asp:Label ID="lblCity" runat="server" Text="City:" Font-Size="Large"
ForeColor="#47C2FF"></asp:Label>
</td>
<td style="width: 135px">
<asp:DropDownList ID="ddlCity" runat="server" DataSourceID="SqlDataSourceCity"
DataTextField="City" DataValueField="Number">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceCity" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringBars %>" SelectCommand="SELECT * FROM [City] ORDER BY [City]"></asp:SqlDataSource>
</td>
<td style="width: 220px; position: relative; text-align: left; vertical-align: middle;">
<asp:Button ID="btnCitySearch" runat="server" Text="Search" />
</td>
</tr>
<tr>
<td style="width: 220px" class="style2" draggable="true">
<asp:Label ID="lblRandomBar" runat="server"></asp:Label>
</td>
<td style="width: 135px">
</td>
<td style="width: 220px">
</td>
</tr>
</table>
</p>
</asp:Content>
Code Behind Random Bar.aspx.vb
Public Class Featured_Bar
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnCitySearch_Click(sender As Object, e As EventArgs) Handles btnCitySearch.Click
End Sub
Protected Sub GVRandomBars_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GVRandomBars.SelectedIndexChanged
End Sub
Protected Sub btnCitySearch_DataBinding(sender As Object, e As EventArgs) Handles btnCitySearch.DataBinding
lblRandomBar.Text = GVRandomBars.DataKeys(0).Value.ToString()
End Sub
End Class

Related

Multi-parameter SqlDatasource search not returning any records

I have an odd problem. I have a gridview attached to a sqldatasource that I send three possible parameters to. The search works fine if I search the item number but if I search for the first name or last name without the item number it does not return anything. The SQL works fine when I test it in SQL management studio but does not when I test it in visual studio in the search form.
Any assistance in solving this will be appreciated. Thanks for your time.
<table style="width: 100%;">
<tr>
<td>Caller Search</td>
<td>
<asp:Label ID="ITEMsearchlable" runat="server" Text="ITEM#"></asp:Label><br />
<asp:TextBox ID="ITEM_NUMsearch" runat="server"></asp:TextBox></td>
<td>
<asp:Label ID="ofname_label" runat="server" Text="First name"></asp:Label><br />
<asp:TextBox ID="search_fname" runat="server" CssClass="uppercase"></asp:TextBox></td>
<td><asp:Label ID="olname_label" runat="server" Text="Last name"></asp:Label><br />
<asp:TextBox ID="search_lname" runat="server" CssClass="uppercase"></asp:TextBox></td>
<td>
<asp:Button ID="search_btn" runat="server" Text="Offender Caller" /></td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" Width="771px" EmptyDataText="No record found">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ITEM_NUM" HeaderText="ITEM_NUM" SortExpression="ITEM_NUM" />
<asp:BoundField DataField="NAME_FIRST" HeaderText="NAME_FIRST" SortExpression="NAME_FIRST" />
<asp:BoundField DataField="NAME_LAST" HeaderText="NAME_LAST" SortExpression="NAME_LAST" />
<asp:BoundField DataField="CALLER_ID" HeaderText="CALLER_ID" SortExpression="CALLER_ID" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
SelectCommand="SELECT DISTINCT
ORDERS.ITEM_NUM,
ORDERS.NAME_FIRST,
ORDERS.NAME_LAST,
VICTIM_CALL_LOG.CALLER_ID
FROM ORDERS LEFT OUTER JOIN
VICTIM_CALL_LOG ON ORDERS.ITEM_NUM = VICTIM_CALL_LOG.ITEM_NUM WHERE ((ORDERS.ITEM_NUM = #ITEM_NUM)
OR (ORDERS.NAME_FIRST LIKE '%' + #NAME_FIRST + '%') OR (ORDERS.NAME_LAST LIKE '%' + #NAME_LAST + '%'))">
<SelectParameters>
<asp:ControlParameter ControlID="ITEM_NUMsearch" Name="ITEM_NUM" PropertyName="Text" Type="Int32" />
<asp:ControlParameter ControlID="search_fname" DefaultValue="NULL" Name="NAME_FIRST" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="search_lname" DefaultValue="NULL" Name="NAME_LAST" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
You need to give the numeric parameter a default value too:
<asp:ControlParameter ControlID="ITEM_NUMsearch" DefaultValue="-1" Name="ITEM_NUM" PropertyName="Text" Type="Int32" />
I used "-1" because I guessed it would never be an actual value in the database, so that needs to be checked.
Note that having a DefaultValue of "NULL" in the string parameters is actually the string "NULL", not the database version of NULL. To do that properly, I suspect that you would have to use code-behind instead of <asp> controls. In the meantime, a default value of "12345" could be a better choice, just in case someone has a name with "null" in it - Null is an actual last name for some people: How does a surname of Null cause problems in many databases?

Why doesn't my page refresh when selecting different Drop Down List Data

Built a simple page linked to a SQL data source with two drop down lists. I'm very new at ASP.NET so excuse my simple newbie errors. At least I'm learning. Anyway object is to have 2 drop down lists, select a last name, and a company name using the common Northwind Database. I'm using the empID and custID as sql parameters. I didn't want the page to load the grid initially so I hid that and also created a clear button. When i run the page it will pull the correct data but when I select a different last name the page pulls the original data. Can someone help me understand where my mistake is?
asp.net code:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<header><h1>Welcome to my First SQL Data Source Page</h1></header>
<h3>Select a Value from both drop Down Lists to find the orders that employee made</h3>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="LastName" DataValueField="EmployeeID" BackColor="#00CCFF" Height="25px" Width="200px">
<asp:ListItem>--Select Last Name--</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [LastName], [EmployeeID] FROM [Employees]"></asp:SqlDataSource>
<br />
<br />
<asp:DropDownList ID="DropDownList2" runat="server" AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="CompanyName" DataValueField="CustomerID" BackColor="#00CCFF" Height="25px" Width="200px">
<asp:ListItem>--Select Company Name--</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CompanyName], [CustomerID] FROM [Customers]"></asp:SqlDataSource>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM ORDERS
WHERE
EmployeeID = #P1
AND
CustomerID = #P2
">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="P1" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DropDownList2" Name="P2" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="OrderID" DataSourceID="SqlDataSource3"
EmptyDataText="There were no orders by this employee">
<alternatingrowstyle backcolor="#0066FF"
forecolor="DarkBlue"
font-italic="true"/>
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID" InsertVisible="False" ReadOnly="True" SortExpression="OrderID" />
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID" />
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" SortExpression="EmployeeID" />
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate" SortExpression="OrderDate" />
<asp:BoundField DataField="RequiredDate" HeaderText="RequiredDate" SortExpression="RequiredDate" />
<asp:BoundField DataField="ShippedDate" HeaderText="ShippedDate" SortExpression="ShippedDate" />
<asp:BoundField DataField="ShipVia" HeaderText="ShipVia" SortExpression="ShipVia" />
<asp:BoundField DataField="Freight" HeaderText="Freight" SortExpression="Freight" />
<asp:BoundField DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" />
<asp:BoundField DataField="ShipAddress" HeaderText="ShipAddress" SortExpression="ShipAddress" />
<asp:BoundField DataField="ShipCity" HeaderText="ShipCity" SortExpression="ShipCity" />
<asp:BoundField DataField="ShipRegion" HeaderText="ShipRegion" SortExpression="ShipRegion" />
<asp:BoundField DataField="ShipPostalCode" HeaderText="ShipPostalCode" SortExpression="ShipPostalCode" />
<asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry" SortExpression="ShipCountry" />
</Columns>
<HeaderStyle BackColor="#0066FF" ForeColor="White" />
</asp:GridView>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Search" BackColor="#00CCFF" BorderStyle="Inset" EnableTheming="True" Height="30px" Width="150px" />
<br />
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="Clear" BackColor="#00CCFF" BorderStyle="Inset" Height="30px" Width="150px" />
</div>
</form>
</body>
</html>
Visual Basic Code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
GridView1.Visible = False
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
GridView1.Visible = True
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
GridView1.Visible = False
End Sub
End Class
Use the Page.IsPostBack method to check whether it is a fresh load or in response to user action. Hide only when loading the page first time.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack() Then GridView1.Visible = False
End Sub

showing/hiding a row in the master-detail grid depending on selection of drop down list TELERIK

Required system: i'm trying to create a master detail grid in telerik where if the user changes his/her selection on a drop down list in the master grid, the row underneath his/her current row in the details grid appears, and if his/her selection changes again it would disappear.
background information: this system was designed to allow the end user (petrol station auditor) to inspect petrol station, and if he/she happens to find a violation he/she would immediately identify what action should be taken.i've decided to create a checklist with a drop down menu where if the user finds a violation he/she would change the drop down list appears and the procedure that has to be performed due to the violation is shown.
problem: i'm trying to create an event using selectedindexchanged in the master grid depending on the drop down list selection. if the dropdown list selection is "in violation" the row would appear in the details grid, otherwise it would disappear. the value i'm using to map the master-details rows to each other is called "SRS".
when trying to obtain the row index with variable "rowIndex", i find an error regarding a type change from one type to another performing my typecasting. i've tried rigorously to solve the issue with no results.
i would be very grateful if someone could provide the code to resolve my issue
NOTE: i will highlight the problematic line of code
vb code (problematic code):
Protected Sub SqlDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource.Selecting
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
**PROBLEMATIC LINE** ------------------------> Dim rowIndex As Integer = CType(CType(sender, RadDropDownList).Parent.Parent, GridViewRow).RowIndex
Dim SRSText As String = RadGrid1.MasterTableView.Items(rowIndex).Cells(3).Text
If sender.SelectedValue = "in violation" Then
SqlDataSource1.SelectParameters.Add(":SRSText", SRSText)
RadGrid1.MasterTableView.DetailTables(0).DataSource = SqlDataSource1
RadGrid1.MasterTableView.DetailTables(0).DataBind()
Else
End If
End Sub
End Class
accompanying ASPX code, for further information:
<%# Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
</asp:ScriptReference>
</Scripts>
</telerik:RadScriptManager>
<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
</telerik:RadStyleSheetManager>
<telerik:RadTextBox ID="RadTextBox1" runat="server" AutoPostBack="True" LabelWidth="64px"
Resize="None" Text="please enter the PFS number" Width="160px">
</telerik:RadTextBox>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<asp:SqlDataSource ID="SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM "CHECKLIST"">
</asp:SqlDataSource>
<p>
</p>
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" DataSourceID="SqlDataSource"
GridLines="None" AllowMultiRowSelection="True" AutoGenerateColumns="False">
<ExportSettings>
<Pdf>
<PageHeader>
<LeftCell Text=""></LeftCell>
<MiddleCell Text=""></MiddleCell>
<RightCell Text=""></RightCell>
</PageHeader>
<PageFooter>
<LeftCell Text=""></LeftCell>
<MiddleCell Text=""></MiddleCell>
<RightCell Text=""></RightCell>
</PageFooter>
</Pdf>
</ExportSettings>
<ClientSettings EnablePostBackOnRowClick="True" EnableRowHoverStyle="True">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView DataKeyNames="INSPECTIONNO" DataSourceID="SqlDataSource">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<DetailTables>
<telerik:GridTableView AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
Width="100%">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="SRS" MasterKeyField="SRS"></telerik:GridRelationFields>
</ParentTableRelation>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<BatchEditingSettings EditType="Cell"></BatchEditingSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</telerik:GridTableView> </DetailTables>
<Columns>
<telerik:GridBoundColumn DataField="PFSNO" DataType="System.Decimal" FilterControlAltText="Filter PFSNO column"
HeaderText="PFSNO" SortExpression="PFSNO" UniqueName="PFSNO">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="INSPECTIONNO" DataType="System.Decimal" FilterControlAltText="Filter INSPECTIONNO column"
HeaderText="INSPECTIONNO" ReadOnly="True" SortExpression="INSPECTIONNO" UniqueName="INSPECTIONNO">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="INPECTIONDATENTIME" FilterControlAltText="Filter INPECTIONDATENTIME column"
HeaderText="INPECTIONDATENTIME" SortExpression="INPECTIONDATENTIME" UniqueName="INPECTIONDATENTIME">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SRS" DataType="System.Decimal" FilterControlAltText="Filter SRS column"
HeaderText="SRS" SortExpression="SRS" UniqueName="SRS">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="VIOLATIONTYPE" FilterControlAltText="Filter VIOLATIONTYPE column"
HeaderText="VIOLATIONTYPE" SortExpression="VIOLATIONTYPE" UniqueName="VIOLATIONTYPE">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="VIOLATIONDESCRIPTION" FilterControlAltText="Filter VIOLATIONDESCRIPTION column"
HeaderText="VIOLATIONDESCRIPTION" SortExpression="VIOLATIONDESCRIPTION" UniqueName="VIOLATIONDESCRIPTION">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="REMARKS" FilterControlAltText="Filter REMARKS column"
HeaderText="REMARKS" SortExpression="REMARKS" UniqueName="REMARKS">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ITEM" FilterControlAltText="Filter ITEM column"
HeaderText="ITEM" SortExpression="ITEM" UniqueName="ITEM">
</telerik:GridBoundColumn>
<telerik:GridAttachmentColumn FileName="attachment"
FilterControlAltText="Filter column column" HeaderText="audit status-"
UniqueName="column">
</telerik:GridAttachmentColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<telerik:RadDropDownList ID="violDrop" runat="server" DataSourceID="dd2_SqlDataSource1" DataTextField="LISTITEM" DataValueField="LISTITEM" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true"/>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
<BatchEditingSettings EditType="Cell"></BatchEditingSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM "MEMO" WHERE ("SRS" = :SRS)">
<SelectParameters>
<asp:ControlParameter ControlID="RadGrid1" Name="SRS" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dd2_SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT "LISTITEM" FROM "DROPDOWNLIST"">
</asp:SqlDataSource>
</asp:Content>
Please try with the below code snippet.
Let me know if any concern.
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim item As GridDataItem = TryCast(TryCast(sender, DropDownList).NamingContainer, GridDataItem)
Dim index As Integer = item.ItemIndex
'Access current row index here
End Sub
First of all thanks for the reply
Unfortunately, the code snippet that you have provided didn't work for my case, it gave me an error message stating "object reference was not set to an instance of an object"
Note:I copied and pasted the code changing the name iof the index variable

very strange issue; different results from same table

I am binding a gridview with some column from a database table, but it shows different results in Pane and in Gridview. see the attachted images.
see the marked records why they are different, although they are comming from the same table.
But yes for binding gridview I am using this query
SELECT mtblbuilding_budget_data.building_id,
mtblbuilding_budget_data.building_name,
mtblbuilding_budget_data.sanctioned_dpr,
mtblbuilding_budget_data.sanctioned_contract,
mtblblock.block_name
FROM mtblbuilding_budget_data
LEFT JOIN mtblblock
ON mtblblock.block_id = mtblbuilding_budget_data.block_id
WHERE mtblbuilding_budget_data.sfti_id = #SFTI_Id
AND mtblbuilding_budget_data.spmu_id = #SPMU_Id
ORDER BY mtblbuilding_budget_data.block_id
aspx code
<asp:TemplateField HeaderText="Sanction (DPR)">
<ItemTemplate>
<%#GetQTY1(float.Parse(Eval("Sanctioned_DPR").ToString())).ToString("N2")%>
</ItemTemplate>
<FooterTemplate>
<%#GetTotalQTY1().ToString("N2")%>
</FooterTemplate>
<FooterStyle HorizontalAlign="Right" />
<HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sanction (Contract)">
<ItemTemplate>
<%#GetQTY2(float.Parse(Eval("Sanctioned_Contract").ToString())).ToString("N2")%>
</ItemTemplate>
<FooterTemplate>
<%#GetTotalQTY2().ToString("N2")%>
</FooterTemplate>
<FooterStyle HorizontalAlign="Right" />
<HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" />
</asp:TemplateField>
Your grigview is rounding the values, check the next column on the same lines, it also as different results.
check the properties of your gridview e disable the round option.
check the properties of your gridview e disable the round option. That's the solution..

Where parameters in EntitydataSource from dropdown control

Using the following markup, my details view is not populating when the dropdown is selected.
The id for the where parameter is to come from the dropdwon selected value.It appears that the control parameter is not functioning properly.
<asp:UpdatePanel ID="updtEditContact" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlContacttoEdit" runat="server" CssClass="dropdowns"
AutoPostBack="True" ClientIDMode="Static"/>
<asp:DetailsView ID="dvEditContacts" runat="server" Height="50px" Width="125px"
AutoGenerateEditButton="True" CssClass="mGrid"/>
<asp:EntityDataSource ID="edsSelectedContact" runat="server" ConnectionString="name=webEntities"
DefaultContainerName="webEntities" EnableFlattening="False"
EntitySetName="contacts">
<WhereParameters>
<asp:ControlParameter ControlID="ddlContactToEdit" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rblAddEditContact" EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="ddlContacttoEdit" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
Upon further research, which was tedious as there isn't a lot of the actual EntityDataSource control since all us probably do most of our EF work in the code behind, there were three issues
I did not have a where attribute in the EDS markup
The "Type" in the WhereParameter needs to be DBType
The Name Attribute of the WhereParameter much match the variable in the Where statement in the EDS markup
Here is the code that works:
<asp:UpdatePanel ID="updtEditContact" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlContacttoEdit" runat="server" CssClass="dropdowns"
AutoPostBack="True" ClientIDMode="Static"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rblAddEditContact" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
<br />
<asp:UpdatePanel ID="updatEditContactDetail" runat="server">
<ContentTemplate>
<asp:DetailsView ID="dvEditContacts" runat="server" Height="50px" Width="300px"
DataSourceID="edsSelectedContact" DataKeyNames="Id" Visible="False"
CssClass="mDetail" FieldHeaderStyle-CssClass="fieldheader"
ItemStyle-CssClass="itemvalues" CommandRowStyle-CssClass="cmdRow"
EditRowStyle-CssClass="editvalues" ClientIDMode="Static"
InsertRowStyle-CssClass="insertvalues" RowStyle-CssClass="rowvalues"/>
<asp:EntityDataSource ID="edsSelectedContact" runat="server" ConnectionString="name=webEntities"
DefaultContainerName="webEntities" EnableFlattening="False"
EntitySetName="contacts" Where="it.Id = #ID">
<WhereParameters>
<asp:ControlParameter ControlID="ddlContactToEdit" Name="ID" PropertyName="SelectedValue" DbType="Int32"/>
</WhereParameters>
</asp:EntityDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlContacttoEdit" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>