Category Archives: DynamicDataManager

DynamicDataManager

[RESOLVED]can you use the RequiredFieldValidator with a GridView data control in Visual Web Developer?

I'm new to Visual Web Developer.  I've created a web form with a GridView
displaying information from a SQL table, and enabled editing. Now I'd like
to add validation to several fields. I've tried using the
RequiredFieldValidator but am not having much luck. Could the reason be
that the GridView doesn't use TextBoxes per se? Rather I see it uses
asp:BoundFields with DataField attributes, not TextBoxes with id attributes.

My goal is to be able to build web forms that interact with SQL tables. If you know of an easier/better way to do it than I'm attempting,
please let me know

Thanks for any help/direction

Christian

to your reqfieldvalidators you need to use TemplateFields instead of boundfields .. 

<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
    <EditItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server"
            Text='<%# Bind("FirstName") %>'></asp:TextBox>
//Here you can use your validator ..
<asp:RequiredFieldValidator runat="server" id="reqName" controltovalidate="TextBox1" errormessage="Please enter your name!" />
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server"
            Text='<%# Bind("FirstName") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
Thanks to everyone for their replies.

FYI: The http://msdn.microsoft.com/en-us/library/bb332381.aspx link looked very promising but the article was from back in 2006-2007. I contacted the author, Scott Mitchell, to ask if the series of articles was still relevant. I'm sharing his reply here:

"Hi Christian. I wouldn’t recommend using Typed DataSets, which is the technology my tutorials detailed. It’s a defunct technology at this point.

Instead, I’d recommend using either Linq-to-SQL or Entity Framework. Scott Guthrie has a multi-part tutorial on using Linq-to-SQL:

http://scottonwriting.net/sowblog/archive/2010/07/27/links-to-scott-guthrie-s-using-linq-to-sql-tutorials.aspx

"

Thought I’d share this.  BTW, when I tried to convert from BoundFields to TemplateFields, as Akii suggested and Mr. Mitchell’s tutorial demonstrated, I wound up with DynamicData tags instead, so the RequiredFieldValidator still didn’t work.

Back to the drawing board …

Chris

Hi Christian,

According to your description, you are have using the DynamicData tags, and you want to validate it.

If so, please refer to the following code:

<%@ 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">
  protected void Page_Init(object sender, EventArgs e)
  {
    DynamicDataManager1.RegisterControl(CustomersGridView);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>DynamicField Sample</title>
  <link href="~/Site.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
    <div>

      <h2><%= CustomersDataSource.TableName%> Table</h2>

      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />

      <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
        HeaderText="List of validation errors"  />
      <asp:DynamicValidator runat="server" ID="DynamicValidator1"
        ControlToValidate="CustomersGridView" Display="None" />

      <asp:GridView ID="CustomersGridView" runat="server"
        AutoGenerateColumns="false"
        AutoGenerateEditButton="true"
        AutoGenerateDeleteButton="true"
        DataSourceID="CustomersDataSource"
        AllowPaging="true"
        AllowSorting="true"
        CssClass="gridview">
        <Columns>
          <asp:DynamicField DataField="CustomerID" />
          <asp:DynamicField DataField="FirstName" />
          <asp:DynamicField DataField="LastName" />
        </Columns>
      </asp:GridView>

      <!-- This example uses Microsoft SQL Server and connects   -->
      <!-- to the AdventureWorksLT sample database.              -->
      <asp:LinqDataSource ID="CustomersDataSource" runat="server"
        TableName="Customers"
        ContextTypeName="AdventureWorksLTDataContext"
        EnableUpdate="true"
        EnableDelete="true" >
      </asp:LinqDataSource>

    </div>
  </form>
</body>
</html>

There have a tutorial about validation control in gridview, please try to refer to it:
http://msdn.microsoft.com/en-us/library/bb426882.aspx

Hope it helps.

If it can’t help you, please post your sample code to here, maybe somebody can help you.

Best Regards,
Terry Guo

[RESOLVED]vs2010 toolbox controls

I am working as a beginner in vs2010 for asp.net 4.0.I see  controls such as Dynamiccontrol,Dynamicdatamanager.

I wanted to work with it but could not get good example on it and I saw Pressbook but not available.could suggest

link for getting good examples on it.Thanks in advance

well I did go through ,got other useful material but not

the one I wanted for dynamiccontrol control and dynamicdatamanager control of toolbox.

sorry I did not get my answer.

Hi srm

srm2009

am working as a beginner in vs2010 for asp.net 4.0.I see  controls such as Dynamiccontrol,Dynamicdatamanager.

You could get detailed information about
DynamicControl
and
DynamicDataManager
here,

If you want to learn other controls in the toolbox, you could search in
MSDN
, you will get detailed information about them.

hope it helps you,

Regards