1 Replies - 4616 Views - Last Post: 10 June 2009 - 01:42 PM Rate Topic: -----

#1 Mavirick   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 72
  • Joined: 18-February 08

GridView Trouble [Solved]

Posted 10 June 2009 - 01:02 PM

Edit: Nevermind, solved this. See my reply for the (dumb) solution.

I hope I'm posting this in the right place--this is ASP.NET w/ C#, and didn't know which forum to choose. The code is mostly ASP.NET, though, so here I am. I'm pretty new to .NET altogether, so bear with me if this is a silly problem.

I wrote this gridview freehand first, with C# methods to query our SQL database for the values and a Delete Command that manually called a delete statement. Then I started fooling around with all of Visual Studio's built in functions, and thought I had the edit function to a good place, textboxes where I wanted them and DropDownLists where I needed them. However, I needed to access controls within the GridView object when rows were being updated, and I started trying to figure out which event would be best to utilize for that purpose. None of them were responding. I've tried RowEditing, RowDataBinding, RowDataBound, PreRender, even Sorting and Sorted don't respond. I've no idea why.

I set up the page with a label and then the GridView so that the GridView's events could be implemented to change the text of the label, thus showing me whether they were being called or not. When nothing was happening, I trashed the whole page and remade it all through Visual Studio's Designer, so that actual coding was minimal. Here's the ASP.NET for the GridView object (gvRegistration):
	<br />
	<br />
	<br />
	<asp:Label ID="OutputLabel" runat="server" Text="No commands yet..."></asp:Label>
	<br />
	<br />
	<br />
	<br />
<asp:GridView ID="gvRegistration" runat="server" DataSourceID="DSRegistration" 
		AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
		DataKeyNames="registrationid" Width="604px" CaptionAlign="Top" 
		CellPadding="3" Font-Size="8pt">
		<Columns>
			<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
			<asp:TemplateField HeaderText="Registration ID" SortExpression="registrationid">
				<ItemTemplate>
					<asp:Label ID="Label1" runat="server" Text='<%# Bind("registrationid") %>'></asp:Label>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:Label ID="Label1" runat="server" Text='<%# Eval("registrationid") %>'></asp:Label>
				</EditItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Name" SortExpression="customer_name">
				<ItemTemplate>
					<asp:Label ID="Label2" runat="server" Text='<%# Bind("customer_name") %>'></asp:Label>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("customer_name") %>'></asp:TextBox>
				</EditItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Email" SortExpression="user_email_address">
				<ItemTemplate>
					<asp:Label ID="Label3" runat="server" Text='<%# Bind("user_email_address") %>'></asp:Label>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:TextBox ID="TextBox2" runat="server" 
						Text='<%# Bind("user_email_address") %>'></asp:TextBox>
				</EditItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="EEID" SortExpression="device_number">
				<ItemTemplate>
					<asp:Label ID="Label4" runat="server" Text='<%# Bind("device_number") %>'></asp:Label>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("device_number") %>'></asp:TextBox>
				</EditItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Carrier" SortExpression="carrier_name">
				<ItemTemplate>
					<asp:Label ID="Label5" runat="server" Text='<%# Bind("carrier_name") %>'></asp:Label>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("carrier_name") %>'></asp:TextBox>
				</EditItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Manufacturer" SortExpression="manufacturer_name">
				<ItemTemplate>
					<asp:Label ID="Label6" runat="server" Text='<%# Bind("manufacturer_name") %>'></asp:Label>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:TextBox ID="TextBox5" runat="server" 
						Text='<%# Bind("manufacturer_name") %>'></asp:TextBox>
				</EditItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Model #" SortExpression="model_no">
				<ItemTemplate>
					<asp:Label ID="Label7" runat="server" Text='<%# Bind("model_no") %>'></asp:Label>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("model_no") %>'></asp:TextBox>
				</EditItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Created" SortExpression="createdate">
				<ItemTemplate>
					<asp:Label ID="Label8" runat="server" Text='<%# Bind("createdate") %>'></asp:Label>
				</ItemTemplate>
				<EditItemTemplate>
					<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("createdate") %>'></asp:TextBox>
				</EditItemTemplate>
			</asp:TemplateField>
		</Columns>
	</asp:GridView>



The data is provided through an SQL Connection (GSRegistration), which, suffice to say, works. But events are never fired, or, if they are, the way I'm coding this isn't working. Here's the entirety of my C# code, in which I've been testing various event handlers:
protected void Page_Load(object sender, EventArgs e)
	{
	}

	protected void gvRegistration_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		OutputLabel.Text = "Data Bound.";
	}

	void gvRegistration_RowEditing(Object sender, GridViewEditEventArgs e)
	{
		OutputLabel.Text = "Editing...";
	}

	protected void gvRegistration_PreRender(GridViewRowEventArgs e)
	{
		OutputLabel.Text = "PreRender.";
	}

	protected void gvRegistration_Sorting(object sender, GridViewSortEventArgs e)
	{
		OutputLabel.Text = "Sorting.";
	}



OutputLabel's text is never changed. How do I get these event handlers to work?

Note: I didn't actually change all the edit templates for the GridView object in this Designer-generated version, but without working event handlers, it hardly matters.

I appreciate any suggestions! Thanks!
Mavirick

P.S. This page is using a masterpage; I'm not sure if that makes a difference.

This post has been edited by Mavirick: 10 June 2009 - 01:43 PM


Is This A Good Question/Topic? 0
  • +

Replies To: GridView Trouble [Solved]

#2 Mavirick   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 72
  • Joined: 18-February 08

Re: GridView Trouble [Solved]

Posted 10 June 2009 - 01:42 PM

Turns out it was a beginner mistake. Apparently, one must assign the event handler he just wrote to the GridView object's event (even though the names match...?) in Visual Studio's properties.

Posted Image

Thanks anyway!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1