DataBinding in User Control

B

bpd

I have a user control embedded in a gridview as an EditItemTemplate.
When updating, the value is not saved to the database. I have an
SQLDataSource attached to the Gridview. Can someone point me to a good
example or discussion about the two way databinding. I use C#. thanks
 
B

bpd

bpd said:
I have a user control embedded in a gridview as an EditItemTemplate.
When updating, the value is not saved to the database. I have an
SQLDataSource attached to the Gridview. Can someone point me to a good
example or discussion about the two way databinding. I use C#. thanks

My source is as follows:
User Control
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="uc_Gridview_Percentage_Textbox.ascx.cs"
Inherits="uc_Gridview_Percentage_Textbox" %>
<asp:TextBox ID="gvtxtPCT" runat="server" Text='<%# Bind("modifier")
%>' CausesValidation="True" CssClass="gridview_edit_percentage"
MaxLength="7"></asp:TextBox>
<asp:RequiredFieldValidator ID="gvrfvPCT" runat="server"
ControlToValidate="gvtxtPCT"
ErrorMessage="Percentage is Required" >*</asp:RequiredFieldValidator>
&nbsp;&nbsp;
<asp:RangeValidator ID="gvrgvPCT" runat="server"
ControlToValidate="gvtxtPCT" ErrorMessage="Percentage must be between
-100.00 and 100.00" MaximumValue="100.00" MinimumValue="-100.00"
SetFocusOnError="True" Type="Currency">*</asp:RangeValidator>

User Control Code Behind
using System;
using System.Data;
using System.ComponentModel;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class uc_Gridview_Percentage_Textbox :
System.Web.UI.UserControl
{
[Bindable(true, BindingDirection.TwoWay)]
public string percent
{
get { return gvtxtPCT.Text; }
set { gvtxtPCT.Text = value; }
}

protected void Page_Load(object sender, EventArgs e)
{
}
}

Gridview
....
<asp:TemplateField HeaderText="Percentage"
SortExpression="modifier">
<EditItemTemplate>
<uc2:uc_Gridview_Percentage_Textbox
ID="Uc_Gridview_Percentage_Textbox1" percent='<%# Bind("modifier") %>'
runat="server" EnableViewState="true" />
</EditItemTemplate>
<HeaderStyle CssClass="gridview_general_header" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("modifier") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top