delete record from table only not affect in database - vb.net

If I try to delete record from table but how to use it, I don't know.
In a radgrid I hav use delete link if I have press delete it's I'll be work but I have try to next level of delete.
If I press delete that data I'll be delete on the grid but it's not affect on Sql database but we don't store data from other table can explain how to use it.
<Telerik:RadGrid ID="GVUpload" runat="server" AllowMultiRowSelection="false" GridLines="None"
CellPadding="1" CellSpacing="1" HeaderStyle-HorizontalAlign="Center" Skin="WebBlue"
AllowPaging="true" PageSize="1000" Height="360PX" Width="100%">
<ClientSettings EnableRowHoverStyle="true">
<Selecting AllowRowSelect="false" />
<Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="2" />
<Resizing AllowColumnResize="true" />
</ClientSettings>
<MasterTableView AutoGenerateColumns="false" DataKeyNames="pendingdump_gid">
<Columns>
<Telerik:GridTemplateColumn HeaderText="Select" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ItemStyle-Width="10%" HeaderStyle-Width="10%" >
<HeaderTemplate>
<asp:CheckBox id="chkall" Text="Select" runat="server" Checked="false" onclick="javascript:select_deselectAll (this.checked, this.id, 'chkall','chkupload');" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkupload" runat="server" CausesValidation="false" Checked="false" onclick="javascript:select_deselectAll (this.checked, this.id, 'chkall','chkupload');" />
</ItemTemplate>
</Telerik:GridTemplateColumn>
<Telerik:GridBoundColumn DataField="pendingdump_gid" HeaderText="Cust ID" Visible="false"
ItemStyle-HorizontalAlign="Center">
</Telerik:GridBoundColumn>
<Telerik:GridBoundColumn DataField="pendingdump_date" HeaderText="Date" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="10%" HeaderStyle-Width="10%" ></Telerik:GridBoundColumn>
<Telerik:GridBoundColumn DataField="pendingdump_refno" HeaderText="Ref.No." ItemStyle-HorizontalAlign="Left" ItemStyle-Width="30%" HeaderStyle-Width="20%" ></Telerik:GridBoundColumn>
<Telerik:GridBoundColumn DataField="pendingdump_name" HeaderText="Party's Name" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="20%" HeaderStyle-Width="10%" ></Telerik:GridBoundColumn>
<Telerik:GridBoundColumn DataField="pendingdump_amount" HeaderText="Pending Amount" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="20%" HeaderStyle-Width="10%" ></Telerik:GridBoundColumn>
<Telerik:GridBoundColumn DataField="pendingdump_duedate" HeaderText="Due On" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="20%" HeaderStyle-Width="10%" ></Telerik:GridBoundColumn>
<Telerik:GridBoundColumn DataField="pendingdump_overduedays" HeaderText="Overdue by Days" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="20%" HeaderStyle-Width="20%" ></Telerik:GridBoundColumn>
<Telerik:GridTemplateColumn HeaderText="Action" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ItemStyle-Width="30%" HeaderStyle-Width="20%" >
<ItemTemplate>
<asp:LinkButton ID="lnkbtnDelete" runat="server" Text="Delete" CausesValidation="false" ToolTip="Click to Delete"
OnClientClick="javascript:return confirmDelete();" CommandName="lnkbtnDelete" CommandArgument=''
<%# DataBinder.Eval(Container.DataItem, "pendingdump_gid") %>'>
</asp:LinkButton>
</ItemTemplate>
</Telerik:GridTemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" />
</MasterTableView>
</Telerik:RadGrid>
Protected Sub GVUpload_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles GVUpload.ItemCommand
lblerrmsg.Text = ""
If e.CommandName = "lnkbtnDelete" Then
Gobjdbconn.OpenConn()
MsSql = ""
MsSql = "Delete vsolv_tmp_tpendingdump where pendingdump_gid = '" & e.CommandArgument() & "' and pendingdump_isremoved = 'N'"
MnResult = Gobjdbconn.ExecuteNonQuerySQL(MsSql)
If MnResult = 1 Then
lblerrmsg.Text = "Record Deleted Successfully"
Else
lblerrmsg.Text = "Record not Deleted"
End If
POPSummary()
End If
End Sub

Related

index Gridview Attribute onclic with button hidden

I need select row in gridview with a button hidden, but without postback because i need that stay on position clicked in gridview, this step i got it, but when i clicked on row capture index = 0, but when i click in button (no hidden in this time), capture correct index, how can I do this, thanks for your help or any idea.
my code is:
aspx:
<asp:UpdatePanel ID="UPGrvConfident" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="table-responsive" id="gridDentalNetworkContainer" style="overflow: auto; height: 207px; cursor: pointer; padding: 0px">
<asp:GridView ID="gridDentalNetwork" EnableViewState="true" AllowSorting="false" runat="server" GridLines="None" Width="100%"
EmptyDataText="No hay elementos a mostrar." AutoGenerateColumns="false" ClientIDMode="Static"
DataKeyNames="numero" ShowHeaderWhenEmpty="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-BackColor="Gainsboro" HeaderStyle-BorderWidth="2px" RowStyle-BackColor="White"
RowStyle-BorderColor="White" RowStyle-Font-Size="Smaller" RowStyle-Font-Bold="false" CellPadding="3" CellSpacing="0">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" CommandName="Delete" CausesValidation="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Numero" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
<asp:BoundField DataField="Nombre" HeaderText="Nombre" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
<asp:BoundField DataField="Identificacion" HeaderText="Identificación" ItemStyle-Width="10%" HeaderStyle-Width="10%" />
<asp:BoundField DataField="Msg" HeaderText="Nombre">
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ApellidoPaterno" HeaderText="Primer Apellido" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
<asp:BoundField DataField="ApellidoMaterno" HeaderText="Segundo Apellido" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
<asp:BoundField DataField="Contrato" HeaderText="Contrato" />
<asp:BoundField DataField="contratocanal" HeaderText="Contratante" ItemStyle-Width="242px" HeaderStyle-Width="242px">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Titular" HeaderText="Usuario Principal">
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="NroDoc" HeaderText="nro_row" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
<asp:BoundField DataField="NroPariente" HeaderText="nro_pariente" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
<asp:BoundField DataField="NroPol" HeaderText="nro_pol" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" HeaderStyle-Width="5px" />
<asp:BoundField DataField="NroAseg" HeaderText="nro_aseg" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
<asp:BoundField DataField="TxtRed" HeaderText="fec_nac" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
<asp:BoundField DataField="Plan" HeaderText="Plan">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="fec_alta" HeaderText="Fecha Ingreso" ItemStyle-Width="96px" HeaderStyle-Width="96px">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<AlternatingRowStyle BackColor="#f2f2f2" />
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
aspx.vb (code behind)
RowdataBound
Protected Sub gridDentalNetwork_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gridDentalNetwork.RowDataBound
'e.Row.Cells(0).Style("display") = "none"
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes("onmouseover") = "this.style.cursor='hand';this.style.textDecoration='underline';"
e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';"
Dim btnSelect As Button = TryCast(e.Row.FindControl("btnSelect"), Button)
btnSelect.CommandArgument = e.Row.RowIndex.ToString()
'e.Row.Attributes("onclick") = String.Format("document.getElementById('{0}').click();", btnSelect.ClientID)
e.Row.Attributes.Add("onclick", "document.getElementById('" & btnSelect.ClientID & "').value = '" & e.Row.RowIndex.ToString() & "'; alert(document.getElementById('" & btnSelect.ClientID & "').value); darClick();")
'e.Row.Attributes.Add("onclick", "var dato = document.getElementById('btnSelect').value; '<%Session['temp']='+ dato +';%>'; alert('<%=Session['temp']%>');")
'e.Row.Attributes("onclick") = String.Format("document.getElementById('{0}').click();", btnSelect.ClientID)
'e.Row.Attributes("onclick") = Page.ClientScript.GetPostBackClientHyperlink(gridDentalNetwork, "Select$" + e.Row.RowIndex.ToString())
'e.Row.Attributes.Add("onclick", String.Format("document.getElementById('{0}').click();", btnSelect.ClientID))
e.Row.ToolTip = "Clic para seleccionar"
End If
End Sub
Method: I am using RowDeleting for commandField.
Protected Sub gridDentalNetwork_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles gridDentalNetwork.RowDeleting
Dim ListBiored As List(Of MClienteSimple) = New List(Of MClienteSimple)
Dim grvfila As GridViewRow
Dim indexx As String = Session("index")
grvfila = gridDentalNetwork.Rows(e.RowIndex)
Dim lstClientesConf As New MClienteDentalNetwork
lstClientesConf = DirectCast(Session("ClientesConf"), List(Of MClienteDentalNetwork))(grvfila.DataItemIndex)
...etc..etc
End Sub

Changing Hyperlink text in VB code for Gridview

In the VB code below, I'm trying to set the Hyperlink hypNote's text as "Add Note" when text is null. However it is not working. As a test, I've even set the Hyperlink text as "Test" and tried:
If hypNote.text = "Test" Then
hypNote.text = "Add Note"
End If
But still it doesn't work. Here's my code..
<asp:Panel ID="pnlOrders" runat="server">
<asp:Image ID="LiveOrders" alt="Live Gif" runat="server" class="extrasButton" ImageUrl="~/files/images/liveOrders.gif" />
<asp:SqlDataSource ID="DSOrders" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" SelectCommand="SELECT TOP (100) PERCENT tblOrders.OrderID, tblOrders.stallmessage, tblOrders.price, tblAccounts.city, tblAccounts.postcode, tblOrders.phoneNo, tblOrders.tblNo, tblOrders.info, tblOrders.orderDate, tblOrders.orderStatus, tblOrders.type, tblOrders.timeFor, tblOrders.paid, tblOrders.tblNo
FROM tblOrders INNER JOIN tblAccounts ON tblOrders.accountID = tblAccounts.AccountID
WHERE tblOrders.orderStatus='Completed'
ORDER BY tblOrders.timeFor ASC">
</asp:SqlDataSource>
<asp:GridView ID="gdvOrders" width="100%" runat="server" style="font-size:1.5em" ShowHeaderWhenEmpty="True" EmptyDataText="No orders" AllowPaging="True" AutoGenerateColumns="False" CssClass="mGrid" DataKeyNames="orderID" DataSourceID="DSOrders" PageSize="20" AllowSorting="True">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField HeaderText="Order">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("stallMessage") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="price" HeaderText="Price" />
<asp:BoundField DataField="phoneNo" HeaderText="Phone No" />
<asp:TemplateField HeaderText="Address/Table No.">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("tblNo") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-ForeColor="Red" HeaderText="Note">
<ItemTemplate>
<asp:HyperLink ID="hypNote" style="Font-Size:20px; color:Red;" runat="server" NavigateUrl='<%# "~/editNote.aspx?note=" & Eval("info").ToString & "&orderID=" & Eval("orderID").ToString %>' ><%# Eval("info") %></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="type" HeaderText="Type" />
<asp:BoundField DataField="orderDate" DataFormatString="{0: H:mm:ss}" HeaderText="Order Time" SortExpression="orderDate" />
<asp:BoundField DataField="timeFor" DataFormatString="{0: H:mm:ss}" HeaderText="Time For" SortExpression="timeFor" />
<asp:BoundField DataField="paid" HeaderText="Paid" />
<asp:TemplateField ShowHeader="True">
<ItemTemplate>
<asp:ImageButton visible="true" ID="lnkSent" runat="server" CausesValidation="False"
onclientclick="return confirm('Mark As Sent?');"
ImageUrl="~/files/images/icons/sendIcon.png" onclick="lnkSent_Click"></asp:ImageButton>
<asp:HiddenField ID="hidnOrderID" runat="server" Value='<%# Eval("orderID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
Protected Sub gdvOrders_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gdvOrders.RowDataBound
For Each r As GridViewRow in gdvOrders.Rows
If r.RowType = DataControlRowType.DataRow Then
Dim hypNote As Hyperlink
hypNote = r.Cells(4).FindControl("hypNote")
If hypNote.text = "" Then
hypNote.text = "Add Note"
End If
End If
Next r
End Sub
Additionally, I wish to change the text color of the Hyperlink when "Add Note" is displayed.
I figured out my mistake. I changed this line to:
<asp:HyperLink ID="hypNote" style="Font-Size:20px; color:Red;" text='<%# Eval("info") %>' runat="server" NavigateUrl='<%# "~/editNote.aspx?note=" & Eval("info").ToString & "&orderID=" & Eval("orderID").ToString %>' ></asp:HyperLink>
I didn't have text= in there.
All worked fine then.

GridView SelectParameter from code behind

I am using VB.NET webforms.
I have a GridView which brings data from Database when the page loads. The SQLDataSource with Select SQL is as follows:
<asp:SqlDataSource
ID="ScopeDataSource"
runat="server"
ConnectionString="<%$ ConnectionStrings:SQLServerConnectionString %>"
SelectCommand="SELECT [SCO_LINENUM], [SCO_LINETEXT], [SCO_SCOPEID], [SCO_TAB1LINK], [SCO_TAB2LINK], [SCO_TAB3LINK] FROM [SCOPE] WHERE [SCO_SCOPEID] = 'AAAREN02'"></asp:SqlDataSource>
My GridView is as follows:
<asp:GridView
ID="ScopeGrid"
runat="server"
DataSourceID="ScopeDataSource"
AutoGenerateColumns="False"
GridLines="None"
DataKeyNames="SCO_SCOPEID, SCO_LINENUM">
<Columns>
<asp:BoundField DataField="SCO_LINENUM" HeaderText="Sr#" SortExpression="SCO_LINENUM">
<HeaderStyle Height="40px" />
<ItemStyle Width="30px" />
</asp:BoundField>
<asp:BoundField DataField="SCO_LINETEXT" HeaderText="Parameter.." SortExpression="SCO_LINETEXT">
<HeaderStyle Height="40px" />
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Operator Values...........">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="DropDownMargin">
<asp:ListItem>BETWEEN</asp:ListItem>
<asp:ListItem>EQUALTO</asp:ListItem>
<asp:ListItem>GREATERTHAN</asp:ListItem>
<asp:ListItem>LESSTHAN</asp:ListItem>
</asp:DropDownList>
<asp:TextBox runat="server" ID="RangeStart" Text="None" Width="50px" CssClass="TextBoxMargin"></asp:TextBox>
<asp:TextBox runat="server" ID="RangeEnd" Text="None" Width="50px"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Height="40px" CssClass="WhiteSpacePreserve" />
</asp:TemplateField>
<asp:BoundField DataField="SCO_SCOPEID" HeaderText="ScopeID" SortExpression="SCO_SCOPEID">
<HeaderStyle CssClass="hidegrid" />
<ItemStyle CssClass="hidegrid" />
</asp:BoundField>
<asp:BoundField DataField="SCO_TAB1LINK" HeaderText="Tab1" SortExpression="SCO_TAB1LINK" />
<asp:BoundField DataField="SCO_TAB2LINK" HeaderText="Tab2" SortExpression="SCO_TAB2LINK" />
<asp:BoundField DataField="SCO_TAB3LINK" HeaderText="Tab3" SortExpression="SCO_TAB3LINK" />
</Columns>
</asp:GridView>
As seen in above SQLDataSource, the WHERE clause is hard-coded. I want to make this dynamic by passing a variable to the WHERE clause from code-behind. Also My Page_Load event is empty. So far, since the SQLDataSource WHERE clause is hard-coded in my aspx I can see the data in gridview but I don't know how to send a variable to it from code-behind?
Something like this would work.
Change your select command to
SELECT [SCO_LINENUM], [SCO_LINETEXT], [SCO_SCOPEID], [SCO_TAB1LINK], [SCO_TAB2LINK], [SCO_TAB3LINK] FROM [SCOPE] WHERE [SCO_SCOPEID] = #SCO_SCOPEID
Then do like
ScopeDataSource.SelectParameters("SCO_SCOPEID").DefaultValue = Your value

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

Loop through gridview getting error

I have a gridview that I am trying to loop through to get the values to update and store in my database. Gridview code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
Width="1020px" EnableTheming="True" PageSize="25" CellPadding="4"
ForeColor="#333333" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Column1" HeaderText="Col1" ReadOnly="True" >
<ItemStyle Width="35px" />
</asp:BoundField>
<asp:BoundField DataField="Column2" HeaderText="Col2" />
<asp:BoundField DataField="Column3" HeaderText="Col3" />
<asp:BoundField DataField="Column4" HeaderText="Col4" />
<asp:BoundField DataField="Column5" HeaderText="Col5" />
<asp:TemplateField HeaderText="Col6">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Column6") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text="$"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Column6", "{0:f}") %>' CssClass="boxright"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:BoundField DataField="Column7" ReadOnly="True" >
<ItemStyle Width="35px" />
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
<PagerSettings Mode="NextPreviousFirstLast" />
<PagerStyle BackColor="#003399" ForeColor="White" HorizontalAlign="Left" />
<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>
I am using a button click event to trigger the stored sql procedure to update my table as follows...
Protected Sub btnB_Save_Click(sender As Object, e As EventArgs) Handles btnB_Save.Click
Dim gvRow As GridViewRow
Dim str As String = ""
For Each gvRow As GridViewRow In gv_Budgets.Rows
str = ((str + gvRow.Cells(0).Text) + (gvRow.Cells(1).Text) + (gvRow.Cells(2).Text) + (gvRow.Cells(3).Text) + (gvRow.Cells(4).Text) + (gvRow.Cells(6).Text))
Dim dtRow As TextBox = CType(gvRow.FindControl("TextBox1"), TextBox)
Response.Write(dtRow.Text)
dt = dal.ExecuteStoredProc(DAL.dbType.SqlServer, "UpdateData", "#col1", str + gvRow.Cells(0).Text, "#col2", str + gvRow.Cells(1).Text, "#col3", str + gvRow.Cells(2).Text, "#col4", str + gvRow.Cells(3).Text, "#col5", str + gvRow.Cells(4).Text, "#col6", dtRow.Text, "#col7", str + gvRow.Cells(6).Text, "#txt1", Textbox2.Text, "#txt2", Textbox3.Text)
Next
End Sub
However, I keep getting those blue syntax error lines under my "dt(datatable)" expression... Any ideas on how or why this is doing this?
Well the "Variable gvRow hides..." error is happening because you've declared gvRow outside the loop and then redeclared it in the definition of the loop.
Dim gvRow As GridViewRow ' First declaration
Dim str As String = ""
For Each gvRow As GridViewRow In gv_Budgets.Rows ' Skip the "As GridViewRow here
The other error is coming from your expression:
dt = dal.ExecuteStoredProc( ...
I'm assuming (because you don't have it listed) that dt is some global variable of type DataTable somewhere. In this case it looks like your sProc is returning a string and attempting to insert it into a datatable object. Make sure your sProc returns a valid datatable. In the meantime you may try to insert the result into a string just to get things working until you can work that out.