RadGrid change column header not working - radgrid

I am trying to change the column header. When I do so it does not show the radgrid at all. If I comment the code inside of rdMain_PreRender the grid show up fine. Am I doing something wrong.
<telerik:RadGrid runat="server" ID="rdMain" AutoGenerateColumns="false" AllowPaging="true" Skin="Metro" OnPreRender="rdMain_PreRender" DataSourceID="MainSource" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
<MasterTableView DataKeyNames="ID" CommandItemDisplay="None">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
<telerik:GridBoundColumn DataField="Location" HeaderText="Location" ReadOnly="true" />
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" />
<telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" />
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
protected void rdMain_PreRender(object sender, EventArgs e)
{
var masterTableView = rdMain.MasterTableView;
var column = masterTableView.GetColumn("Phone");
column.HeaderText = "TelePhone";
masterTableView.Rebind();
}

Set the unique name of the columns in the grid and try using the next line of code in PreRender:
rdMain.Columns.FindByUniqueName("Phone").HeaderText = "TelePhone";
Hope it works.

Related

GridCommandEventArgs items have no data values

I have a RadGrid with which I need to add, update, and delete data. I've gotten the functionality to work, but I also need to do some checking on the data before it gets added/updated, including setting a field based on other data. I also want to log what was done.
My Insert functionality is working. The RadGrid is as follows:
<telerik:RadGrid ID="CarrierRadGrid" runat="server" AllowFilteringByColumn="True" AllowPaging="False" Width="100%" Height="800px" PageSize="20" da
AllowSorting="True" DataSourceID="CarrierData" ShowStatusBar="True"
OnInsertCommand="CarrierRadGrid_InsertCommand" OnItemInserted="CarrierRadGrid_ItemInserted" AllowAutomaticInserts="true"
OnUpdateCommand="CarrierRadGrid_UpdateCommand" OnItemUpdated="CarrierRadGrid_ItemUpdated" AllowAutomaticUpdates="true"
OnDeleteCommand="CarrierRadGrid_DeleteCommand" OnItemDeleted="CarrierRadGrid_ItemDeleted" AllowAutomaticDeletes="true"
Skin="Telerik" AutoGenerateColumns="False" AutoGenerateEditColumn="false" AutoGenerateDeleteColumn="false">
<ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="false">
<Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" FrozenColumnsCount="5" />
<Selecting AllowRowSelect="true" />
<Resizing AllowColumnResize="true" AllowResizeToFit="true" />
<ClientEvents OnRowDeleting="void 0" />
</ClientSettings>
<GroupingSettings CaseSensitive="false" />
<ExportSettings HideStructureColumns="true">
</ExportSettings>
<HeaderContextMenu EnableAutoScroll="False">
</HeaderContextMenu>
<MasterTableView DataKeyNames="CarrierScacID" DataSourceID="CarrierData" AllowAutomaticInserts="true" AllowAutomaticDeletes="True" AllowAutomaticUpdates="true"
CommandItemDisplay="Top" HierarchyLoadMode="ServerOnDemand" EditMode="InPlace">
<CommandItemSettings
ShowExportToWordButton="false"
ShowExportToCsvButton="false"
ShowExportToPdfButton="false"
ShowAddNewRecordButton="true">
</CommandItemSettings>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" CancelText="Cancel" EditText="Edit" InsertText="Add"
UpdateText="Update" HeaderStyle-Width="30px" UniqueName="CarrierEditButton" />
<telerik:GridClientDeleteColumn ButtonType="ImageButton" Text="Delete" HeaderStyle-Width="30px" UniqueName="CarrierDeleteButton"
ConfirmTextFields="CarrierScac" ConfirmTextFormatString="Are you sure you want to delete carrier {0}?" CommandName="Delete" />
<telerik:GridBoundColumn DataField="CarrierScacID" HeaderText="CarrierScacID" UniqueName="CarrierScacID" ReadOnly="True" Display="false" />
<telerik:GridTemplateColumn>
<EditItemTemplate>
<telerik:RadLabel runat="server" ID="CarrierScac" Text='<% #Bind("CarrierScac") %>' ViewStateMode="Disabled" Enabled="false" />
</EditItemTemplate>
<InsertItemTemplate>
<telerik:RadTextBox ID="CarrierScac" runat="server" Text='<% #Bind("CarrierScac") %>' />
</InsertItemTemplate>
<ItemTemplate>
<telerik:RadLabel runat="server" ID="CarrierScac" Text='<% #Bind("CarrierScac") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="CarrierScac" HeaderText="SCAC" UniqueName="CarrierScac" FilterControlWidth="40px" HeaderStyle-Width="75px" />
<telerik:GridBoundColumn DataField="CarrierName" HeaderText="Carrier Name" UniqueName="CarrierName" ItemStyle-Wrap="false"
HeaderStyle-Width="200px" FilterControlWidth="160px" FilterControlAltText="Filter by Carrier Name" SortExpression="CarrierName" />
<telerik:GridBoundColumn DataField="Address" HeaderText="Address" UniqueName="Address" ItemStyle-Wrap="false"
HeaderStyle-Width="200px" FilterControlWidth="160px" FilterControlAltText="Filter by Address" SortExpression="Address" />
<telerik:GridBoundColumn DataField="City" HeaderText="City" UniqueName="City" HeaderStyle-Width="100px" />
<telerik:GridBoundColumn DataField="State" HeaderText="State" UniqueName="State" FilterControlWidth="30px" HeaderStyle-Width="65px" />
<telerik:GridBoundColumn DataField="ZIP" HeaderText="ZIP" UniqueName="ZIP" FilterControlWidth="55px" HeaderStyle-Width="90px" />
<telerik:GridBoundColumn DataField="Country" HeaderText="Country" UniqueName="Country" FilterControlWidth="55px" HeaderStyle-Width="90px" />
<telerik:GridBoundColumn DataField="Contact" HeaderText="Contact" UniqueName="Contact" ItemStyle-Wrap="false" HeaderStyle-Width="110px" />
<telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" UniqueName="Phone" ItemStyle-Wrap="false" HeaderStyle-Width="115px" />
<telerik:GridBoundColumn DataField="Fax" HeaderText="Fax" UniqueName="Fax" ItemStyle-Wrap="false" HeaderStyle-Width="115px" />
<telerik:GridBoundColumn DataField="User" HeaderText="User" UniqueName="User" HeaderStyle-Width="120px" ReadOnly="true" />
<telerik:GridBoundColumn DataField="Update" HeaderText="Update" UniqueName="Update" ItemStyle-Wrap="false" HeaderStyle-Width="230px" ReadOnly="true" />
<telerik:GridBoundColumn DataField="Comments" HeaderText="Comments" UniqueName="Comments" ItemStyle-Wrap="false" HeaderStyle-Width="230px" ReadOnly="true" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
In code-behind, I have the following:
Protected Sub CarrierRadGrid_InsertCommand(sender As Object, e As GridCommandEventArgs)
e = SetCommentsField(e)
End Sub
Protected Sub CarrierRadGrid_ItemInserted(sender As Object, e As GridInsertedEventArgs)
Dim msg As String = String.Format("New carrier (Carrier Code: {0}) added to the database.", e.Item.Cells(6).Text)
Log(msg)
MessageBox(msg)
End Sub
Private Shared Function SetCommentsField(e As GridCommandEventArgs) As GridCommandEventArgs
If String.IsNullOrEmpty(e.Item.Cells(18).Text) Then
Dim update As String = e.Item.Cells(17).Text
If Not String.IsNullOrEmpty(update) Then
e.Item.Cells(18).Text = String.Format("Modified by {0}", update)
End If
End If
Return e
End Function
But when debugging, I find all of the e.Item.Cells Text properties are " ". Yet the record added to the database has the data I put into the fields, as it should.
What could be missing? Or extra?
EDIT: Including the whole RadGrid, instead of only the part I thought was relevant.
Below are two options to access the cell data.
This accesses the newly inserted data using a hashtable/dictionary. It only retrieves data from EditItems so read-only rows are not included
This converts your editItem to a data item and accesses the current cell which you will find is consistently because the data has not been put there yet. THe data entered only exists in the edit items.
Protected Sub CarrierRadGrid_InsertCommand(sender As Object, e As GridCommandEventArgs)
'1
Dim insertValues As New Hashtable()
CType(e.Item, GridEditableItem).ExtractValues(insertValues)
Dim dd = insertValues("CarrierScac")
'2
Dim item As GridDataItem = CType(e.Item, GridDataItem)
Dim itemD = item("CarrierScac").Text
e = SetCommentsField(e)
End Sub
The above should get you what you need I suspect, however to add some color
Telerik uses to denote an empty/null cell text field which makes sense here because the cell text you are trying to grab does not exist. It IS empty and you ARE accessing it. The fields you are accessing, however, are read only and there does not appear to be a default value. Are you setting that elsewhere? I've included a function below that checks for String.IsNullOrEmpty and that we use frequently to spare some logic. I'd put it in a safe place and consume it as needed because empty cells in a radgrid will never actually be string.empty.
Public Function RadGridCellIsNullOrEmpty(value As String) As Boolean
value = value.Trim()
Return (String.IsNullOrEmpty(value) OrElse String.IsNullOrWhiteSpace(value) OrElse value.Contains(" "))
End Function
Private Shared Function SetCommentsField(byRef e As GridCommandEventArgs) As GridCommandEventArgs
If RadGridCellIsNullOrEmpty(e.Item.Cells(18).Text) Then
Dim update As String = e.Item.Cells(17).Text
If Not RadGridCellIsNullOrEmpty(update) Then
e.Item.Cells(18).Text = String.Format("Modified by {0}", update)
End If
End If
Return e
End Function

RadButton stays visible on the page all the time after Radgrid reload

I have a page where I search the data and populate RadGrid.
The page has a button to export the data into Excel.
Everything works fine, data is exporting. I can search as well.
I hide the button and RadGrid in the code when the Grid is empty:
btnExport.Visible = false;
gridDisplay.Visible = false;
However, when RadGrid is empty, it becomes hidden but button is still displayed.
I build the RadGrid inside of the RadAjaxPanel:
<telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" LoadingPanelID="RadAjaxLoadingPanel2">
<telerik:RadGrid
RenderMode="Lightweight"
runat="server"
ID="grdMoss2Merchants"
AllowPaging="True"
AllowSorting="true"
PagerStyle-AlwaysVisible="true"
OnNeedDataSource="BindToDatasource"
OnSortCommand="grdMoss2Merchants_SortCommand"
ViewStateMode="Enabled"
AutoGenerateColumns="false"
OnPageIndexChanged="grdMoss2Merchants_ChangePage"
ClientSettings-Scrolling-ScrollHeight="360px">
<GroupingSettings CaseSensitive="false"/>
<ExportSettings HideStructureColumns="true" ExportOnlyData="true" OpenInNewWindow="true" Excel-Format="Xlsx" IgnorePaging="true" FileName="Moss2Merchants">
<Excel WorksheetName="Moss2Merchants" Format="Xlsx" AutoFitColumnWidth="AutoFitAll" />
</ExportSettings>
<ClientSettings EnableRowHoverStyle="true">
<Scrolling AllowScroll="true" UseStaticHeaders="True"/>
<ClientEvents OnKeyPress="keyPress" />
</ClientSettings>
<SortingSettings EnableSkinSortStyles="false" />
<HeaderStyle Width="160px" CssClass="grdHeader" ForeColor="#2E6E9E" />
<MasterTableView AllowNaturalSort="false">
<PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" PageSizes="10,25,50,100" />
<Columns>
<telerik:GridBoundColumn DataField="Moss2 MID" HeaderText="MOSS2 MID" AllowSorting="false" DataFormatString="{0:#}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DBA" HeaderText="DBA" HeaderStyle-Width="250px">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Original MID" HeaderText="ORIGINAL MID" AllowSorting="false" DataFormatString="{0:#}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="BoardingDate"
DataType="System.DateTime"
HtmlEncode="false"
DataFormatString="{0:MM/dd/yyyy}"
SortExpression="BoardingDate"
UniqueName="BoardingDate"
HeaderText="BOARDING DATE"
HeaderStyle-Width="170px"
ShowFilterIcon="false"
/>
<telerik:GridBoundColumn DataField="Status" HeaderText="STATUS" AllowSorting="false"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
This just a simple code to generate a button outside of the Grid:
<div>
<telerik:RadButton ID="btnExport" runat="server" OnClick = "btnExportClick" Text="Export To Excel" CausesValidation="false"/>
<br/>
</div>
I'm not sure what I'm doing wrong here.
Need some assistance

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

delete record from table only not affect in database

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

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