I am attaching a SqlDataSource to a grid view.
Inside my SqlDataSource I use control parameters to filter the data, I have a button to filter the data using the text inside the textboxes.
The main problem is that nothing is being filtered.
Here is my aspx:
<%# Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Template.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head_breadcrumb" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentInfoBarName" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentInfoBarApprovalStatus" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ContentInfoBarState" runat="server">
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="content" runat="server">
<tr>
<td width="100" align="right" bgcolor="#eeeeee" class="header1">Power Web</td>
<td align="center" bgcolor="#FFFFFF">
<asp:TextBox ID="txtNB" runat="server"></asp:TextBox>
<asp:TextBox ID="txtSystem" runat="server"></asp:TextBox>
<asp:TextBox ID="txtObjectID" runat="server"></asp:TextBox>
<asp:TextBox ID="txtObjectDescription" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" />
<asp:GridView ID="gvwExample" runat="server" OnClick="filter" AutoGenerateColumns="False" DataSourceID="GridDataSource" OnRowDataBound="gvwExample_RowDataBound" CssClass="basix" >
<columns>
<asp:BoundField DataField="NB" HeaderText="NB" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="CLevel" HeaderText="CLevel" />
<asp:BoundField DataField="CC Host" HeaderText="CC Host" />
<asp:BoundField DataField="System" HeaderText="System" />
<asp:BoundField DataField="Object Type" HeaderText="Object Type" />
<asp:BoundField DataField="Object ID" HeaderText="Object ID" />
<asp:BoundField DataField="Object Description" HeaderText="Object Description" />
<asp:BoundField DataField="Excl Mngr" HeaderText="Excl Mngr" />
</columns>
</asp:GridView>
<asp:SqlDataSource ID="GridDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PowerWeb%>"
SelectCommand="SELECT * FROM Table1" FilterExpression="NB LIKE '{0}%' AND System LIKE '{1}%' AND Object ID LIKE '{2}%' AND Object Description LIKE '{3}%'">
<FilterParameters>
<asp:ControlParameter Name="NB" ControlID="txtNB" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
<asp:ControlParameter Name="System" ControlID="txtSystem" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
<asp:ControlParameter Name="Object ID" ControlID="txtObjectID" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
<asp:ControlParameter Name="Object Description" Type="String" ControlID="txtObjectDescription" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
<asp:label ID="lblStatus" runat="server"></asp:label></td>
</tr>
</asp:Content>
And here is my code behind:
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void gvwExample_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int index = GetColumnIndexByName(e.Row, "Excl Mngr");
if (e.Row.Cells[index].Text == "False")
{
e.Row.Cells[index].Text = "";
}
else if(e.Row.Cells[index].Text == "True")
{
e.Row.Cells[index].Text = "Yes";
}
}
}
int GetColumnIndexByName(GridViewRow row, string SearchColumnName)
{
int columnIndex = 0;
foreach (DataControlFieldCell cell in row.Cells)
{
if (cell.ContainingField is BoundField)
{
if (((BoundField)cell.ContainingField).DataField.Equals(SearchColumnName))
{
break;
}
}
columnIndex++;
}
return columnIndex;
}
public void filter(Object sender, EventArgs e)
{
gvwExample.DataSource = GridDataSource;
gvwExample.DataBind();
}
}
EDIT:
The contentplaceholder named content is inside this on my master page:
<asp:UpdatePanel ID="updateMain" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:ContentPlaceHolder ID="content" runat="server"/>
</ContentTemplate>
</asp:UpdatePanel>
Is because this?
Have you tried to remove the UpdatePanel from the Master Page and add it to your page. Best practices recomend that you wrap your content with the update panel, only in the areas you need to update. This way you won't generate much traffic.
In this case, the UpdatePanel, won't bind well with the button inside the content/page, and like so, it won't trigger the update on the update panel.
Related
I want to update all rows of a GridView one time by clicking one button:
aspx:
</asp:ObjectDataSource>
<asp:ListBox ID="ListBoxRoles" runat="server" DataSourceID="ObjectDataSourceAllRoles"
AutoPostBack="true" DataTextField="RoleName" DataValueField="RoleID"
OnSelectedIndexChanged="ListBoxRoles_SelectedIndexChanged">
</asp:ListBox>
<asp:ObjectDataSource ID="ObjectDataSourceRolePermissions" runat="server"
TypeName="RolePermission" SelectMethod="GetRolePermissionByRoleID"
UpdateMethod="UpdateRolePermission">
<SelectParameters>
<asp:ControlParameter ControlID="ListBoxRoles" Name="RoleID" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="ListBoxRoles" Name="RoleID" PropertyName="SelectedValue"
Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridViewRolePermission" SkinID="GridViewSecurity" runat="server" style="width: 100%;"
HeaderStyle-Height="50" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ObjectDataSourceRolePermissions">
<Columns>
<asp:BoundField ItemStyle-HorizontalAlign="Center" DataField="PermissionName" SortExpression="PermissionName" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxRead" runat="server" Checked='<%#Bind("Read") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxUpdate" runat="server" Checked='<%#Bind("Update") %>' />
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
<asp:Button runat="server" ID="ButtonUpdateRolePermissions" Text="Save" OnClick="ButtonUpdateRolePermissions_Click" />
I want to update all rows of the gridview once the ButtonUpdateRolePermissions clicked.
I tried:
protected void ButtonupdateRolePermissions_Click(object sender, EventArgs e)
{
foreach(GridViewRow RolePermission in this.GridViewRolePermission.Rows)
{
this.ObjectDataSourceRolePermissions.Update();
}
}
but the update method not take Update and Read fields into consideration.
I'm trying to change the data of my gridlist on my homepage when you click on a button.. Tried many things nothing works. When I press the button to change gridview data nothing happpens and few secons later I get a error
How it looks: http://prntscr.com/7fa9qh
The Error : http://prntscr.com/7faam0
I have left some code out to make it not all to big, like I only have 2 buttons in code but there are more
list.aspx.cs :
protected void Page_Load(object sender, EventArgs e) {
GvTop2000 usercontrol = (GvTop2000)Page.LoadControl("~/Pages /Usercontrols/ListGv/GvTop2000.ascx");
pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
}
protected void btnTop2000_Click(object sender, EventArgs e) {
pnlGVList.ContentTemplateContainer.Controls.Clear();
GvTop2000 usercontrol = (GvTop2000)Page.LoadControl("~/Pages/Usercontrols/ListGv/GvTop2000.ascx");
pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
pnlGVList.Update();
}
protected void btnNieuw_Click(object sender, EventArgs e) {
pnlGVList.ContentTemplateContainer.Controls.Clear();
GvNieuw usercontrol = (GvNieuw)Page.LoadControl("~/Pages/Usercontrols/ListGv/GvNieuw.ascx");
pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
pnlGVList.Update();
}
list.aspx :
<asp:Content ID="ContentHolderDD" runat="server" ContentPlaceHolderID="ContentHolderDD">
<asp:ScriptManagerProxy ID="smProxy" runat="server" />
<%-- Year selector --%>
<asp:DropDownList ID="ddlJaar" CssClass="ddl" runat="server" DataSourceID="DSYears" DataTextField="top2000jaar" DataValueField="top2000jaar" AutoPostBack="True" />
<asp:SqlDataSource runat="server" ID="DSYears" ConnectionString='<%$ ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>' SelectCommand="sp_get_year" SelectCommandType="StoredProcedure" />
</asp:Content>
<asp:Content ID="ContentPlaceholderButtons" runat="server" ContentPlaceHolderID="ContentPlaceholderButtons">
gvTop2000 usercontrol:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="GvTop2000.ascx.cs" Inherits="Top2000.Pages.Usercontrols.ListGv.GvTop2000" %>
<asp:GridView runat="server" ID="gridList" CellPadding="10" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataSourceID="DSList" AllowPaging="True" PageSize="100" CssClass="GridListings">
<Columns>
<asp:BoundField DataField="positie" HeaderText="Positie" SortExpression="positie"></asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="artiestid" DataNavigateUrlFormatString="Artists.aspx?id={0}" DataTextField="naam" HeaderText="Artiest" />
<asp:HyperLinkField DataNavigateUrlFields="songid" DataNavigateUrlFormatString="Song.aspx?id={0}" DataTextField="titel" HeaderText="Titel" />
<asp:BoundField DataField="jaar" HeaderText="Jaar" SortExpression="jaar"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" ID="DSList" ConnectionString='<%$ ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>' SelectCommand="sp_top2000_year" SelectCommandType="StoredProcedure" >
<SelectParameters>
<asp:ControlParameter PropertyName="SelectedValue" DefaultValue="" Name="YEAR" Type="Int32" ControlID="ContentHolderDD$ddlJaar" />
</SelectParameters>
</asp:SqlDataSource>
<asp:UpdatePanel runat="server" ID="pnlCButtons">
<ContentTemplate>
<asp:Button ID="btnTop2000" runat="server" Text="Top2000" OnClick="btnTop2000_Click" />
<asp:Button ID="btnNieuw" runat="server" Text="Nieuw" OnClick="btnNieuw_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
<asp:Content id="ContentPlaceHolder1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<%-- GridView --%>
<asp:UpdatePanel ID="pnlGVList" runat="server">
<ContentTemplate>
<asp:PlaceHolder runat="server" ID="phGv"/>
</ContentTemplate>
</asp:UpdatePanel>
gvNieuw usercontrol :
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="GvNieuw.ascx.cs" Inherits="Top2000.Pages.Usercontrols.ListGv.GvNieuw" %>
<asp:GridView runat="server" ID="gridList" CellPadding="10" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataSourceID="sqlDS" AllowPaging="True" PageSize="100" CssClass="GridListings" DataKeyNames="songid,top2000jaar,songid1,artiestid1">
<Columns>
<asp:BoundField DataField="songid" HeaderText="songid" SortExpression="songid" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="top2000jaar" HeaderText="top2000jaar" SortExpression="top2000jaar" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="positie" HeaderText="positie" SortExpression="positie" />
<asp:BoundField DataField="songid1" HeaderText="songid1" InsertVisible="False" ReadOnly="True" SortExpression="songid1" />
<asp:BoundField DataField="artiestid" HeaderText="artiestid" SortExpression="artiestid" />
<asp:BoundField DataField="titel" HeaderText="titel" SortExpression="titel" />
<asp:BoundField DataField="jaar" HeaderText="jaar" SortExpression="jaar" />
<asp:BoundField DataField="artiestid1" HeaderText="artiestid1" InsertVisible="False" ReadOnly="True" SortExpression="artiestid1" />
<asp:BoundField DataField="naam" HeaderText="naam" SortExpression="naam" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>" SelectCommand="sp_new_songs_year" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ContentHolderDD$ddlJaar" Name="top2000Year" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
This is a hybrid (MVC and Web forms) Web app to rate doctors. Here is my code for the ratings Web form. Why is there an extra table with the first record under the GridView? It happened after I pressed "Select" in the first row, but why does it stay there after I stop and run it again? It's not a cache problem, because it shows in different browsers. Thanks in advance!
<%# Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="Rating.aspx.cs" Inherits="MidtermApplication.Rating" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ObjectDataSource ID="ObjectDataSourceDoctor" runat="server" DeleteMethod="Remove" InsertMethod="Add" SelectMethod="GetDoctor" TypeName="MidtermApplication.Models.TestApplicationDoctorRepo" UpdateMethod="Update" DataObjectTypeName="MidtermApplication.Models.Doctor">
</asp:ObjectDataSource>
<asp:GridView ID="GridViewDoctor" runat="server" DataSourceID="ObjectDataSourceDoctor" AutoGenerateColumns="False" OnSelectedIndexChanged="GridViewDoctor_SelectedIndexChanged">
<Columns>
<asp:ImageField DataImageUrlField="DoctorPicture" HeaderText="DoctorPicture">
</asp:ImageField>
<asp:BoundField DataField="DoctorName" HeaderText="DoctorName" SortExpression="DoctorName" />
<asp:BoundField DataField="DoctorSpecialty" HeaderText="DoctorSpecialty" SortExpression="DoctorSpecialty" />
<asp:TemplateField HeaderText="Rate Now">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="RateNow" Text="1"></asp:RadioButton>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="RateNow" Text="2"></asp:RadioButton>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="RateNow" Text="3"></asp:RadioButton>
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="RateNow" Text="4"></asp:RadioButton>
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="RateNow" Text="5"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField AccessibleHeaderText="Save Rating" HeaderText="Save Rating" Text="Save" />
<asp:CheckBoxField DataField="fave" HeaderText="Favorite" SortExpression="fave" InsertVisible="False" Visible="True" />
</Columns>
</asp:GridView>
</asp:Content>
Code behind:
namespace MidtermApplication
{
public partial class Rating : System.Web.UI.Page
{
TestApplicationDoctorRepo repo;
protected void Page_Load(object sender, EventArgs e)
{
TestApplicationDoctorRepo.InitApp(this);
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridViewDoctor_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Why is there an extra table with the first record under the GridView?
it is a details view, you can remove it in design mode in visual studio.
Update:
Solution:
You must create a new page, and design this page again.
I have a grid view with a stored procedure set up in SQL.I have three controls 2 dropdown list's and a texbox with jQuery Date picker.My problem is that the gridview isn't showing on pageload. However when I start adding the controls the gridview is suddenly displayed. From debugging, I have speculated that the textbox with the jQuery datepicker does not pass the NULL value to the stored procedure specified, though I am still wondering if it is the cause.This is the code..
Aspx Code:
<div class="datarange">
<asp:DropDownList ID="categoryDDL" AutoPostBack="true" AppendDataBoundItems="true" runat="server">
<asp:ListItem Text="Select Category" Value=" " />
</asp:DropDownList>
<asp:DropDownList ID="brokerDDL" AutoPostBack="true" runat="server"></asp:DropDownList>
<asp:TextBox ID="openDate" AutoPostBack="true" runat="server"></asp:TextBox>
</div>
<br />
<%-- SQL DATA SOURCE PARAMETERS --%>
<asp:SqlDataSource ID="SqlRAListings" runat="server" ConnectionString="<%$ ConnectionStrings:kmc_SalesPipelineConnectionString %>" SelectCommand="RecentlyAddedListings" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="categoryDDL" Name="Category" PropertyName="SelectedValue" Type="String" DefaultValue=" " />
<asp:ControlParameter ControlID="brokerDDL" Name="Broker" PropertyName="SelectedValue" Type="String" DefaultValue=" Select Employee" />
<asp:ControlParameter ControlID="openDate" Name="OpenDate" PropertyName="Text" Type="DateTime" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
<%-- END OF SQL DATA SOURCE PARAMETERS --%>
<%-- GRIDVIEW FOR DISPLAYING RECENTLY ADDED LISTINGS --%>
<asp:GridView ID="ralGridView" runat="server" AllowSorting="True" AutoGenerateColumns="False" OnSelectedIndexChanged="ralGridView_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="Opportunity">
<ItemTemplate>
<a href="/management/opportunity.aspx?id=<%# Eval("ID") %>" target="_blank">
<%# Eval("Opportunity").ToString() != "" ? Eval("Opportunity") : "Opportunity" %>
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="Category" HeaderText="Category"
SortExpression="Category" />
<asp:BoundField DataField="Contact Name" HeaderText="Contact Name"
SortExpression="Contact Name" />
<asp:BoundField DataField="Employee" HeaderText="Employee" SortExpression="Employee" />
<asp:BoundField DataField="Open Date" HeaderText="Open Date" SortExpression="Open Date" />
<asp:TemplateField HeaderText="Opportunity from">
<ItemTemplate>
<%# Eval("LeadID").ToString().Length > 0 == true ? "Lead System" : "Personal Lead" %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDbRAListings" runat="server" ConnectionString="<%$ ConnectionStrings:kmc_SalesPipelineConnectionString %>" SelectCommand="RecentlyAddedListings" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="categoryDDL" Name="Category" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="brokerDDL" Name="Broker" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="openDate" Name="OpenDate" PropertyName="Text" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
<%-- END OF GRID VIEW --%>
</form>
<script type="text/javascript">
$(function () {
var dates = $("#openDate").datepicker({
defaultDate: "+1w",
changeMonth: false,
numberOfMonths: 1
});
});
</script>
C# Code:
namespace KMCWebLMS
{
public partial class RecentlyAssignedLead : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
fillCategoryDropDown();
fillBrokerDropDown();
}
else
{
ralGridView.DataSource = SqlDbRAListings;
ralGridView.DataBind();
}
}
public void fillCategoryDropDown()
{
DataTable categories = new DataTable();
string command = #"SELECT LeadCategory FROM LeadCategory ORDER BY LeadCategory";
ConnectSQL cmd = new ConnectSQL();
SqlDataAdapter adapter = new SqlDataAdapter(cmd.configureSQL(command));
adapter.Fill(categories);
try
{
categoryDDL.DataSource = categories;
categoryDDL.DataTextField = "LeadCategory";
categoryDDL.DataValueField = "LeadCategory";
categoryDDL.DataBind();
}
catch
{
}
}
public void fillBrokerDropDown()
{
DataTable employees = new DataTable();
string command = #"SELECT TOP 100 [Emp_Name] FROM [kmc_SalesPipeline].[dbo].[vwEmployees] ORDER BY Emp_Name";
ConnectSQL cmd = new ConnectSQL();
SqlDataAdapter adapter = new SqlDataAdapter(cmd.configureSQL(command));
adapter.Fill(employees);
try
{
brokerDDL.DataSource = employees;
brokerDDL.DataTextField = "Emp_Name";
brokerDDL.DataValueField = "Emp_Name";
brokerDDL.DataBind();
}
catch
{
}
}
protected void ralGridView_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
But from your code behind , it seems you're populating the gridview only in a postback.
For PageLoad , you're only populating the dropdowns.
Shouldn't this code come
ralGridView.DataSource = SqlDbRAListings;
ralGridView.DataBind();
inside
if (!Page.IsPostBack)
I have found the solution to the problem. To do this, I declared the parameters required for the stored procedure in the Code Behind and set it there accordingly.
//STORED PROCEDURE PARAMETERS
cmd.Parameters.AddWithValue("#OpenDate", OpenDate);
cmd.Parameters.AddWithValue("#Broker", broker);
cmd.Parameters.AddWithValue("#Category", category);
The program will then display the default value on page_load displaying all the data in the gridview. On postback, the specified parameters will be set to the values that are currently stored in the specific control parameters accordingly.
broker = brokerDDL.SelectedValue;
category = categoryDDL.SelectedValue;
ralGridView.DataSource = CreateRecentlyAddedTable();
ralGridView.DataBind();
I'm trying to fetch the data from the gridview according to the row I select for deletion.
I tried this,
string fileName = grdUploadedFiles.Rows[e.RowIndex].Cells[2].ToString();
but it shows the string,
System.Web.UI.WebControls.DataControlFieldCell
What exactly can I do to fetch the filename that I have inserted to the gridview.
Also, this field is not the DataKey.
If your cell not contain any control like label then try this
string fileName = grdUploadedFiles.Rows[e.RowIndex].Cells[2].Text;
You should be calling .Text for the value, per MSDN documentation.
Generally speaking .ToString is overridden by default for Value types. Reference types generally don't override .ToSting with their "values" (what you would commonly access when calling that class).
Here is an example from MSDN:
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void CustomersGridView_RowDeleting
(Object sender, GridViewDeleteEventArgs e)
{
TableCell cell = CustomersGridView.Rows[e.RowIndex].Cells[2];
if (cell.Text == "Beaver")
{
e.Cancel = true;
Message.Text = "You cannot delete customer Beaver.";
}
else
{
Message.Text = "";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>GridView RowDeleting Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>
GridView RowDeleting Example
</h3>
<asp:Label ID="Message" ForeColor="Red" runat="server" />
<br />
<asp:GridView ID="CustomersGridView" runat="server"
DataSourceID="CustomersSqlDataSource"
AutoGenerateColumns="False"
AutoGenerateDeleteButton="True"
OnRowDeleting="CustomersGridView_RowDeleting"
DataKeyNames="CustomerID,AddressID">
<Columns>
<asp:BoundField DataField="FirstName"
HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="City" HeaderText="City"
SortExpression="City" />
<asp:BoundField DataField="StateProvince" HeaderText="State"
SortExpression="StateProvince" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="CustomersSqlDataSource" runat="server"
SelectCommand="SELECT SalesLT.CustomerAddress.CustomerID,
SalesLT.CustomerAddress.AddressID,
SalesLT.Customer.FirstName,
SalesLT.Customer.LastName,
SalesLT.Address.City,
SalesLT.Address.StateProvince
FROM SalesLT.Customer
INNER JOIN SalesLT.CustomerAddress
ON SalesLT.Customer.CustomerID =
SalesLT.CustomerAddress.CustomerID
INNER JOIN SalesLT.Address ON SalesLT.CustomerAddress.AddressID =
SalesLT.Address.AddressID"
DeleteCommand="Delete from SalesLT.CustomerAddress where CustomerID =
#CustomerID and AddressID = #AddressID"
ConnectionString="<%$ ConnectionStrings:AdventureWorksLTConnectionString %>">
<DeleteParameters>
<asp:Parameter Name="AddressID" />
<asp:Parameter Name="CustomerID" />
</DeleteParameters>
</asp:SqlDataSource>
</form>
</body>
</html>