Validators inside datagrid do not fire

  • Thread starter Luis Esteban Valencia
  • Start date
L

Luis Esteban Valencia

I have a asp.net page (C#), with a datagrid. I use template for all columns,
and have <asp:requiredfieldvalidator> in with one of the textboxes, to make
sure it's filled in. However, this validation is not firing, even when I
leave the field empty. Below please find the code:

Code:
<%@ Page Language="C#" Debug="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="C#"  runat="server">

DataSet dsDepartments = new DataSet();
SqlConnection myConnection = new
SqlConnection("server=dbServer;database=Inventory;User
ID=appUser;Password=appPassword;");
SqlDataAdapter myCommand;


private void Page_Load(object Sender, EventArgs e)
{
if (ViewState["sortexpression"] == null)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
}
if (!IsPostBack)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
Response.Write("!IsPostBack");
BindGrid();
}
}

void doSort(object sender, DataGridSortCommandEventArgs e)
{
Response.Write("doSort");
if (ViewState["sortorder"] == " ASC" && ViewState["sortexpression"] ==
e.SortExpression)
{
ViewState["sortorder"] = " DESC";
}
else
{
ViewState["sortorder"] = " ASC";
ViewState["sortexpression"] = e.SortExpression;
}
BindGrid();
}
void doUpdate(object sender, DataGridCommandEventArgs e)
{
TextBox bName;
TextBox bNote;
TextBox bID;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptNote");
bID = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptID");
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
SqlConnection Con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("UPDATE dept SET deptName
= '{0}', deptNote = '{1}' WHERE deptID={2}", bName.Text, bNote.Text,
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex])), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doDelete(object sender, DataGridCommandEventArgs e)
{
long deptID =
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex]);
SqlConnection Con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("DELETE FROM dept WHERE
deptID={0}", deptID), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doEdit(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs  e)
{
dgDepartments.ShowFooter = false;
dgDepartments.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}

void doCancel(object sender, DataGridCommandEventArgs e)
{
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
BindGrid();
}


public void BindGrid()
{
myCommand = new SqlDataAdapter("select * from Dept",
myConnection);
myCommand.Fill(dsDepartments, "Dept");
DataView Source = dsDepartments.Tables["Dept"].DefaultView;
Source.Sort = ViewState["sortexpression"].ToString() +
ViewState["sortorder"].ToString();
dgDepartments.DataSource=Source;
Response.Write("BindGrid()");
dgDepartments.DataBind();
}

protected void doPage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgDepartments.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}

void doInsert(object sender, DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == "Insert" )
{
TextBox bName;
TextBox bNote;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptNote");
SqlConnection Con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("INSERT INTO dept
(deptName, deptNote) VALUES ('{0}', '{1}')", bName.Text, bNote.Text), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}
}
catch
{
}
}


</script>

<head>
<link href="../stylesheet.css" rel="stylesheet" type="text/css">
</head>

<body>
<H1>Departments</H1>
<form runat="server"  id="form1">
<asp:DataGrid
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
PageSize="10"
Width="100%"
DataKeyField="deptID"
PagerStyle-Mode="NextPrev"
PagerStyle-NextPageText="Next"
PagerStyle-PrevPageText="Previous"
PagerStyle-HorizontalAlign="Center"
PagerStyle-Position="TopAndBottom"
runat="server"
ID="dgDepartments"
ShowFooter="true"
ShowHeader="true"
runat="server"
OnPageIndexChanged="doPage"
onUpdateCommand="doUpdate"
onEditCommand="doEdit"
onDeleteCommand="doDelete"
onCancelCommand="doCancel"
onItemCommand="doInsert"
onSortCommand="doSort"<HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign="left" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templatecolumn HeaderText="ID" Visible="true"
SortExpression="deptID">
<itemtemplate>
<%#DataBinder.Eval(Container.DataItem, "deptID")  %>
</itemtemplate>
<edititemtemplate>
<%#DataBinder.Eval(Container.DataItem,"deptID") %>
</edititemtemplate>
</asp:templatecolumn>
<asp:TemplateColumn HeaderText="Name"  SortExpression="deptName"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptName")  %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox text='<%# DataBinder.Eval(Container.DataItem,
"deptName") %>' id="deptName" runat="Server" cssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="Name"
Visible="true" ControlToValidate="deptName" Enabled="true"
ErrorMessage="Required"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</EditItemTemplate>
<footertemplate><asp:textbox id="_deptName" runat="server"
CssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="_Name"
ControlToValidate="_deptName" Error="Fill in a name" Enabled="true"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</footertemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Note"  SortExpression="deptNote"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptNote") %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox cssClass="Text" text='<%#
DataBinder.Eval(Container.DataItem, "deptNote") %>' id="deptNote"
runat="server" />
</EditItemTemplate>
<footertemplate>
<asp:textbox id="_deptNote" runat="server" CssClass="Text" />
</footertemplate>
</asp:TemplateColumn>
<asp:templatecolumn HeaderText="Edit">
<itemtemplate><asp:button CssClass="Text" CommandName="edit"
runat="server"  CausesValidation="false" ID="edit"
Text="Edit"/>&nbsp;<asp:button CssClass="Text" CommandName="delete"
runat="server" ID="delete" Text="Delete" /></itemtemplate>
<edititemtemplate><asp:button CssClass="Text" CommandName="update"
runat="server" CausesValidation="true" ID="update" Text="Save"
/>&nbsp;<asp:button CssClass="Text" CommandName="cancel" runat="server"
CausesValidation="false" ID="cancel" Text="Cancel"/></edititemtemplate>
<footertemplate><asp:button CssClass="Text" Commandname = "Insert"
runat="server" ID="add" Text="Add" /></footertemplate>
</asp:templatecolumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
 
G

Guest

There are problems trying to implement cell by cell validation using the
grid's Validating event architecture. The problem is that the grid is not the
object handling the data. Instead, a TextBox or some other control is the
control managing the changing of the cell contents. One way to implement the
validation at the grid level is to handle the CurrentCellChanged event, and
if the previous cell's value is not proper, then return to that cell.

Also be sure that your client scripting is running ok. Any Client scripting
that have errors, causes no client validation.

Fernando Hunth
Senior Developer
Huddle Group S.A.
(e-mail address removed)



Huddle Group S.A. | Enterprise Technology Services
Microsoft Certified Partner

Ciudad de la Paz 2719

· Piso 6D (C1428CPU)

· Ciudad de Buenos Aires · Argentina
www.huddle.com.ar








Luis Esteban Valencia said:
I have a asp.net page (C#), with a datagrid. I use template for all columns,
and have <asp:requiredfieldvalidator> in with one of the textboxes, to make
sure it's filled in. However, this validation is not firing, even when I
leave the field empty. Below please find the code:

Code:
<%@ Page Language="C#" Debug="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="C#"  runat="server">

DataSet dsDepartments = new DataSet();
SqlConnection myConnection = new
SqlConnection("server=dbServer;database=Inventory;User
ID=appUser;Password=appPassword;");
SqlDataAdapter myCommand;


private void Page_Load(object Sender, EventArgs e)
{
if (ViewState["sortexpression"] == null)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
}
if (!IsPostBack)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
Response.Write("!IsPostBack");
BindGrid();
}
}

void doSort(object sender, DataGridSortCommandEventArgs e)
{
Response.Write("doSort");
if (ViewState["sortorder"] == " ASC" && ViewState["sortexpression"] ==
e.SortExpression)
{
ViewState["sortorder"] = " DESC";
}
else
{
ViewState["sortorder"] = " ASC";
ViewState["sortexpression"] = e.SortExpression;
}
BindGrid();
}
void doUpdate(object sender, DataGridCommandEventArgs e)
{
TextBox bName;
TextBox bNote;
TextBox bID;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptNote");
bID = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptID");
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
SqlConnection Con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("UPDATE dept SET deptName
= '{0}', deptNote = '{1}' WHERE deptID={2}", bName.Text, bNote.Text,
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex])), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doDelete(object sender, DataGridCommandEventArgs e)
{
long deptID =
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex]);
SqlConnection Con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("DELETE FROM dept WHERE
deptID={0}", deptID), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doEdit(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs  e)
{
dgDepartments.ShowFooter = false;
dgDepartments.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}

void doCancel(object sender, DataGridCommandEventArgs e)
{
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
BindGrid();
}


public void BindGrid()
{
myCommand = new SqlDataAdapter("select * from Dept",
myConnection);
myCommand.Fill(dsDepartments, "Dept");
DataView Source = dsDepartments.Tables["Dept"].DefaultView;
Source.Sort = ViewState["sortexpression"].ToString() +
ViewState["sortorder"].ToString();
dgDepartments.DataSource=Source;
Response.Write("BindGrid()");
dgDepartments.DataBind();
}

protected void doPage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgDepartments.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}

void doInsert(object sender, DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == "Insert" )
{
TextBox bName;
TextBox bNote;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptNote");
SqlConnection Con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("INSERT INTO dept
(deptName, deptNote) VALUES ('{0}', '{1}')", bName.Text, bNote.Text), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}
}
catch
{
}
}


</script>

<head>
<link href="../stylesheet.css" rel="stylesheet" type="text/css">
</head>

<body>
<H1>Departments</H1>
<form runat="server"  id="form1">
<asp:DataGrid
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
PageSize="10"
Width="100%"
DataKeyField="deptID"
PagerStyle-Mode="NextPrev"
PagerStyle-NextPageText="Next"
PagerStyle-PrevPageText="Previous"
PagerStyle-HorizontalAlign="Center"
PagerStyle-Position="TopAndBottom"
runat="server"
ID="dgDepartments"
ShowFooter="true"
ShowHeader="true"
runat="server"
OnPageIndexChanged="doPage"
onUpdateCommand="doUpdate"
onEditCommand="doEdit"
onDeleteCommand="doDelete"
onCancelCommand="doCancel"
onItemCommand="doInsert"
onSortCommand="doSort"<HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign="left" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templatecolumn HeaderText="ID" Visible="true"
SortExpression="deptID">
<itemtemplate>
<%#DataBinder.Eval(Container.DataItem, "deptID")  %>
</itemtemplate>
<edititemtemplate>
<%#DataBinder.Eval(Container.DataItem,"deptID") %>
</edititemtemplate>
</asp:templatecolumn>
<asp:TemplateColumn HeaderText="Name"  SortExpression="deptName"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptName")  %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox text='<%# DataBinder.Eval(Container.DataItem,
"deptName") %>' id="deptName" runat="Server" cssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="Name"
Visible="true" ControlToValidate="deptName" Enabled="true"
ErrorMessage="Required"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</EditItemTemplate>
<footertemplate><asp:textbox id="_deptName" runat="server"
CssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="_Name"
ControlToValidate="_deptName" Error="Fill in a name" Enabled="true"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</footertemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Note"  SortExpression="deptNote"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptNote") %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox cssClass="Text" text='<%#
DataBinder.Eval(Container.DataItem, "deptNote") %>' id="deptNote"
runat="server" />
</EditItemTemplate>
<footertemplate>
<asp:textbox id="_deptNote" runat="server" CssClass="Text" />
</footertemplate>
</asp:TemplateColumn>
<asp:templatecolumn HeaderText="Edit">
<itemtemplate><asp:button CssClass="Text" CommandName="edit"
runat="server"  CausesValidation="false" ID="edit"
Text="Edit"/> <asp:button CssClass="Text" CommandName="delete"
runat="server" ID="delete" Text="Delete" /></itemtemplate>
<edititemtemplate><asp:button CssClass="Text" CommandName="update"
runat="server" CausesValidation="true" ID="update" Text="Save"
/> <asp:button CssClass="Text" CommandName="cancel" runat="server"
CausesValidation="false" ID="cancel" Text="Cancel"/></edititemtemplate>
<footertemplate><asp:button CssClass="Text" Commandname = "Insert"
runat="server" ID="add" Text="Add" /></footertemplate>
</asp:templatecolumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>



--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
 
L

Luis Esteban Valencia

How Could I Implement it on the code I have?'
more or less?? a snippet of code?

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
Fernando Hunth said:
There are problems trying to implement cell by cell validation using the
grid's Validating event architecture. The problem is that the grid is not the
object handling the data. Instead, a TextBox or some other control is the
control managing the changing of the cell contents. One way to implement the
validation at the grid level is to handle the CurrentCellChanged event, and
if the previous cell's value is not proper, then return to that cell.

Also be sure that your client scripting is running ok. Any Client scripting
that have errors, causes no client validation.

Fernando Hunth
Senior Developer
Huddle Group S.A.
(e-mail address removed)



Huddle Group S.A. | Enterprise Technology Services
Microsoft Certified Partner

Ciudad de la Paz 2719

· Piso 6D (C1428CPU)

· Ciudad de Buenos Aires · Argentina
www.huddle.com.ar








Luis Esteban Valencia said:
I have a asp.net page (C#), with a datagrid. I use template for all columns,
and have <asp:requiredfieldvalidator> in with one of the textboxes, to make
sure it's filled in. However, this validation is not firing, even when I
leave the field empty. Below please find the code:

Code:
<%@ Page Language="C#" Debug="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="C#"  runat="server">

DataSet dsDepartments = new DataSet();
SqlConnection myConnection = new
SqlConnection("server=dbServer;database=Inventory;User
ID=appUser;Password=appPassword;");
SqlDataAdapter myCommand;


private void Page_Load(object Sender, EventArgs e)
{
if (ViewState["sortexpression"] == null)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
}
if (!IsPostBack)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
Response.Write("!IsPostBack");
BindGrid();
}
}

void doSort(object sender, DataGridSortCommandEventArgs e)
{
Response.Write("doSort");
if (ViewState["sortorder"] == " ASC" && ViewState["sortexpression"] ==
e.SortExpression)
{
ViewState["sortorder"] = " DESC";
}
else
{
ViewState["sortorder"] = " ASC";
ViewState["sortexpression"] = e.SortExpression;
}
BindGrid();
}
void doUpdate(object sender, DataGridCommandEventArgs e)
{
TextBox bName;
TextBox bNote;
TextBox bID;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptNote");
bID = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptID");
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
SqlConnection Con = new
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("UPDATE dept SET deptName
= '{0}', deptNote = '{1}' WHERE deptID={2}", bName.Text, bNote.Text,
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex])), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doDelete(object sender, DataGridCommandEventArgs e)
{
long deptID =
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex]);
SqlConnection Con = new
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("DELETE FROM dept WHERE
deptID={0}", deptID), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doEdit(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs  e)
{
dgDepartments.ShowFooter = false;
dgDepartments.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}

void doCancel(object sender, DataGridCommandEventArgs e)
{
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
BindGrid();
}


public void BindGrid()
{
myCommand = new SqlDataAdapter("select * from Dept",
myConnection);
myCommand.Fill(dsDepartments, "Dept");
DataView Source = dsDepartments.Tables["Dept"].DefaultView;
Source.Sort = ViewState["sortexpression"].ToString() +
ViewState["sortorder"].ToString();
dgDepartments.DataSource=Source;
Response.Write("BindGrid()");
dgDepartments.DataBind();
}

protected void doPage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgDepartments.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}

void doInsert(object sender, DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == "Insert" )
{
TextBox bName;
TextBox bNote;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptNote");
SqlConnection Con = new
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("INSERT INTO dept
(deptName, deptNote) VALUES ('{0}', '{1}')", bName.Text, bNote.Text), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}
}
catch
{
}
}


</script>

<head>
<link href="../stylesheet.css" rel="stylesheet" type="text/css">
</head>

<body>
<H1>Departments</H1>
<form runat="server"  id="form1">
<asp:DataGrid
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
PageSize="10"
Width="100%"
DataKeyField="deptID"
PagerStyle-Mode="NextPrev"
PagerStyle-NextPageText="Next"
PagerStyle-PrevPageText="Previous"
PagerStyle-HorizontalAlign="Center"
PagerStyle-Position="TopAndBottom"
runat="server"
ID="dgDepartments"
ShowFooter="true"
ShowHeader="true"
runat="server"
OnPageIndexChanged="doPage"
onUpdateCommand="doUpdate"
onEditCommand="doEdit"
onDeleteCommand="doDelete"
onCancelCommand="doCancel"
onItemCommand="doInsert"
onSortCommand="doSort"<HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign="left" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templatecolumn HeaderText="ID" Visible="true"
SortExpression="deptID">
<itemtemplate>
<%#DataBinder.Eval(Container.DataItem, "deptID")  %>
</itemtemplate>
<edititemtemplate>
<%#DataBinder.Eval(Container.DataItem,"deptID") %>
</edititemtemplate>
</asp:templatecolumn>
<asp:TemplateColumn HeaderText="Name"  SortExpression="deptName"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptName")  %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox text='<%# DataBinder.Eval(Container.DataItem,
"deptName") %>' id="deptName" runat="Server" cssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="Name"
Visible="true" ControlToValidate="deptName" Enabled="true"
ErrorMessage="Required"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</EditItemTemplate>
<footertemplate><asp:textbox id="_deptName" runat="server"
CssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="_Name"
ControlToValidate="_deptName" Error="Fill in a name" Enabled="true"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</footertemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Note"  SortExpression="deptNote"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptNote") %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox cssClass="Text" text='<%#
DataBinder.Eval(Container.DataItem, "deptNote") %>' id="deptNote"
runat="server" />
</EditItemTemplate>
<footertemplate>
<asp:textbox id="_deptNote" runat="server" CssClass="Text" />
</footertemplate>
</asp:TemplateColumn>
<asp:templatecolumn HeaderText="Edit">
<itemtemplate><asp:button CssClass="Text" CommandName="edit"
runat="server"  CausesValidation="false" ID="edit"
Text="Edit"/> <asp:button CssClass="Text" CommandName="delete"
runat="server" ID="delete" Text="Delete" /></itemtemplate>
<edititemtemplate><asp:button CssClass="Text" CommandName="update"
runat="server" CausesValidation="true" ID="update" Text="Save"
/> <asp:button CssClass="Text" CommandName="cancel" runat="server"
CausesValidation="false" ID="cancel" Text="Cancel"/></edititemtemplate>
<footertemplate><asp:button CssClass="Text" Commandname = "Insert"
runat="server" ID="add" Text="Add" /></footertemplate>
</asp:templatecolumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>



--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
 
G

Guest

Take a look at http://www21.brinkster.com/fhunth/Developers/FAQDatagrid.asp

Luis Esteban Valencia said:
How Could I Implement it on the code I have?'
more or less?? a snippet of code?

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
Fernando Hunth said:
There are problems trying to implement cell by cell validation using the
grid's Validating event architecture. The problem is that the grid is not the
object handling the data. Instead, a TextBox or some other control is the
control managing the changing of the cell contents. One way to implement the
validation at the grid level is to handle the CurrentCellChanged event, and
if the previous cell's value is not proper, then return to that cell.

Also be sure that your client scripting is running ok. Any Client scripting
that have errors, causes no client validation.

Fernando Hunth
Senior Developer
Huddle Group S.A.
(e-mail address removed)



Huddle Group S.A. | Enterprise Technology Services
Microsoft Certified Partner

Ciudad de la Paz 2719

· Piso 6D (C1428CPU)

· Ciudad de Buenos Aires · Argentina
www.huddle.com.ar








Luis Esteban Valencia said:
I have a asp.net page (C#), with a datagrid. I use template for all columns,
and have <asp:requiredfieldvalidator> in with one of the textboxes, to make
sure it's filled in. However, this validation is not firing, even when I
leave the field empty. Below please find the code:

Code:
<%@ Page Language="C#" Debug="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="C#"  runat="server">

DataSet dsDepartments = new DataSet();
SqlConnection myConnection = new
SqlConnection("server=dbServer;database=Inventory;User
ID=appUser;Password=appPassword;");
SqlDataAdapter myCommand;


private void Page_Load(object Sender, EventArgs e)
{
if (ViewState["sortexpression"] == null)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
}
if (!IsPostBack)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
Response.Write("!IsPostBack");
BindGrid();
}
}

void doSort(object sender, DataGridSortCommandEventArgs e)
{
Response.Write("doSort");
if (ViewState["sortorder"] == " ASC" && ViewState["sortexpression"] ==
e.SortExpression)
{
ViewState["sortorder"] = " DESC";
}
else
{
ViewState["sortorder"] = " ASC";
ViewState["sortexpression"] = e.SortExpression;
}
BindGrid();
}
void doUpdate(object sender, DataGridCommandEventArgs e)
{
TextBox bName;
TextBox bNote;
TextBox bID;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptNote");
bID = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptID");
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
SqlConnection Con = new
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("UPDATE dept SET deptName
= '{0}', deptNote = '{1}' WHERE deptID={2}", bName.Text, bNote.Text,
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex])), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doDelete(object sender, DataGridCommandEventArgs e)
{
long deptID =
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex]);
SqlConnection Con = new
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("DELETE FROM dept WHERE
deptID={0}", deptID), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doEdit(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs  e)
{
dgDepartments.ShowFooter = false;
dgDepartments.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}

void doCancel(object sender, DataGridCommandEventArgs e)
{
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
BindGrid();
}


public void BindGrid()
{
myCommand = new SqlDataAdapter("select * from Dept",
myConnection);
myCommand.Fill(dsDepartments, "Dept");
DataView Source = dsDepartments.Tables["Dept"].DefaultView;
Source.Sort = ViewState["sortexpression"].ToString() +
ViewState["sortorder"].ToString();
dgDepartments.DataSource=Source;
Response.Write("BindGrid()");
dgDepartments.DataBind();
}

protected void doPage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgDepartments.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}

void doInsert(object sender, DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == "Insert" )
{
TextBox bName;
TextBox bNote;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptNote");
SqlConnection Con = new
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("INSERT INTO dept
(deptName, deptNote) VALUES ('{0}', '{1}')", bName.Text, bNote.Text), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}
}
catch
{
}
}


</script>

<head>
<link href="../stylesheet.css" rel="stylesheet" type="text/css">
</head>

<body>
<H1>Departments</H1>
<form runat="server"  id="form1">
<asp:DataGrid
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
PageSize="10"
Width="100%"
DataKeyField="deptID"
PagerStyle-Mode="NextPrev"
PagerStyle-NextPageText="Next"
PagerStyle-PrevPageText="Previous"
PagerStyle-HorizontalAlign="Center"
PagerStyle-Position="TopAndBottom"
runat="server"
ID="dgDepartments"
ShowFooter="true"
ShowHeader="true"
runat="server"
OnPageIndexChanged="doPage"
onUpdateCommand="doUpdate"
onEditCommand="doEdit"
onDeleteCommand="doDelete"
onCancelCommand="doCancel"
onItemCommand="doInsert"
onSortCommand="doSort"

<HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign="left" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templatecolumn HeaderText="ID" Visible="true"
SortExpression="deptID">
<itemtemplate>
<%#DataBinder.Eval(Container.DataItem, "deptID")  %>
</itemtemplate>
<edititemtemplate>
<%#DataBinder.Eval(Container.DataItem,"deptID") %>
</edititemtemplate>
</asp:templatecolumn>
<asp:TemplateColumn HeaderText="Name"  SortExpression="deptName"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptName")  %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox text='<%# DataBinder.Eval(Container.DataItem,
"deptName") %>' id="deptName" runat="Server" cssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="Name"
Visible="true" ControlToValidate="deptName" Enabled="true"
ErrorMessage="Required"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</EditItemTemplate>
<footertemplate><asp:textbox id="_deptName" runat="server"
CssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="_Name"
ControlToValidate="_deptName" Error="Fill in a name" Enabled="true"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</footertemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Note"  SortExpression="deptNote"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptNote") %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox cssClass="Text" text='<%#
DataBinder.Eval(Container.DataItem, "deptNote") %>' id="deptNote"
runat="server" />
</EditItemTemplate>
<footertemplate>
<asp:textbox id="_deptNote" runat="server" CssClass="Text" />
</footertemplate>
</asp:TemplateColumn>
<asp:templatecolumn HeaderText="Edit">
<itemtemplate><asp:button CssClass="Text" CommandName="edit"
runat="server"  CausesValidation="false" ID="edit"
Text="Edit"/> <asp:button CssClass="Text" CommandName="delete"
runat="server" ID="delete" Text="Delete" /></itemtemplate>
<edititemtemplate><asp:button CssClass="Text" CommandName="update"
runat="server" CausesValidation="true" ID="update" Text="Save"
/> <asp:button CssClass="Text" CommandName="cancel" runat="server"
CausesValidation="false" ID="cancel" Text="Cancel"/></edititemtemplate>
<footertemplate><asp:button CssClass="Text" Commandname = "Insert"
runat="server" ID="add" Text="Add" /></footertemplate>
</asp:templatecolumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>



--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
 
L

Luis Esteban Valencia

I didnt find anything related. and it says Windows Forms Datagrid???

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
Fernando Hunth said:
Take a look at http://www21.brinkster.com/fhunth/Developers/FAQDatagrid.asp

Luis Esteban Valencia said:
How Could I Implement it on the code I have?'
more or less?? a snippet of code?

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
"Fernando Hunth" <[email protected]> escribió en el
mensaje news:[email protected]...
There are problems trying to implement cell by cell validation using the
grid's Validating event architecture. The problem is that the grid is
not
the
object handling the data. Instead, a TextBox or some other control is the
control managing the changing of the cell contents. One way to
implement
the
validation at the grid level is to handle the CurrentCellChanged
event,
and
if the previous cell's value is not proper, then return to that cell.

Also be sure that your client scripting is running ok. Any Client scripting
that have errors, causes no client validation.

Fernando Hunth
Senior Developer
Huddle Group S.A.
(e-mail address removed)



Huddle Group S.A. | Enterprise Technology Services
Microsoft Certified Partner

Ciudad de la Paz 2719

· Piso 6D (C1428CPU)

· Ciudad de Buenos Aires · Argentina
www.huddle.com.ar








:

I have a asp.net page (C#), with a datagrid. I use template for all columns,
and have <asp:requiredfieldvalidator> in with one of the textboxes,
to
make
sure it's filled in. However, this validation is not firing, even when I
leave the field empty. Below please find the code:

Code:
<%@ Page Language="C#" Debug="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="C#"  runat="server">

DataSet dsDepartments = new DataSet();
SqlConnection myConnection = new
SqlConnection("server=dbServer;database=Inventory;User
ID=appUser;Password=appPassword;");
SqlDataAdapter myCommand;


private void Page_Load(object Sender, EventArgs e)
{
if (ViewState["sortexpression"] == null)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
}
if (!IsPostBack)
{
ViewState["sortexpression"] = "deptName";
ViewState["sortorder"] = " ASC";
Response.Write("!IsPostBack");
BindGrid();
}
}

void doSort(object sender, DataGridSortCommandEventArgs e)
{
Response.Write("doSort");
if (ViewState["sortorder"] == " ASC" &&[/QUOTE] ViewState["sortexpression"]
==[QUOTE]
e.SortExpression)
{
ViewState["sortorder"] = " DESC";
}
else
{
ViewState["sortorder"] = " ASC";
ViewState["sortexpression"] = e.SortExpression;
}
BindGrid();
}
void doUpdate(object sender, DataGridCommandEventArgs e)
{
TextBox bName;
TextBox bNote;
TextBox bID;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptNote");
bID = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("deptID");
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
SqlConnection Con = new
[/QUOTE]
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn[QUOTE]
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("UPDATE dept SET deptName
= '{0}', deptNote = '{1}' WHERE deptID={2}", bName.Text, bNote.Text,
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex])), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doDelete(object sender, DataGridCommandEventArgs e)
{
long deptID =
Convert.ToInt32(dgDepartments.DataKeys[e.Item.ItemIndex]);
SqlConnection Con = new
[/QUOTE]
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn[QUOTE]
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("DELETE FROM dept WHERE
deptID={0}", deptID), Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}

void doEdit(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs  e)
{
dgDepartments.ShowFooter = false;
dgDepartments.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}

void doCancel(object sender, DataGridCommandEventArgs e)
{
dgDepartments.ShowFooter = true;
dgDepartments.EditItemIndex = -1;
BindGrid();
}


public void BindGrid()
{
myCommand = new SqlDataAdapter("select * from Dept",
myConnection);
myCommand.Fill(dsDepartments, "Dept");
DataView Source = dsDepartments.Tables["Dept"].DefaultView;
Source.Sort = ViewState["sortexpression"].ToString() +
ViewState["sortorder"].ToString();
dgDepartments.DataSource=Source;
Response.Write("BindGrid()");
dgDepartments.DataBind();
}

protected void doPage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgDepartments.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}

void doInsert(object sender, DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == "Insert" )
{
TextBox bName;
TextBox bNote;
bName =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptName");
bNote =
(System.Web.UI.WebControls.TextBox)e.Item.FindControl("_deptNote");
SqlConnection Con = new
[/QUOTE]
 SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dbConn[QUOTE]
String"]);
SqlCommand Cmd = new SqlCommand(string.Format("INSERT[/QUOTE] INTO
dept[QUOTE]
(deptName, deptNote) VALUES ('{0}', '{1}')", bName.Text,[/QUOTE] bNote.Text),
Con);[QUOTE]
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
BindGrid();
}
}
catch
{
}
}


</script>

<head>
<link href="../stylesheet.css" rel="stylesheet" type="text/css">
</head>

<body>
<H1>Departments</H1>
<form runat="server"  id="form1">
<asp:DataGrid
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
PageSize="10"
Width="100%"
DataKeyField="deptID"
PagerStyle-Mode="NextPrev"
PagerStyle-NextPageText="Next"
PagerStyle-PrevPageText="Previous"
PagerStyle-HorizontalAlign="Center"
PagerStyle-Position="TopAndBottom"
runat="server"
ID="dgDepartments"
ShowFooter="true"
ShowHeader="true"
runat="server"
OnPageIndexChanged="doPage"
onUpdateCommand="doUpdate"
onEditCommand="doEdit"
onDeleteCommand="doDelete"
onCancelCommand="doCancel"
onItemCommand="doInsert"
onSortCommand="doSort"

<HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign="left" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templatecolumn HeaderText="ID" Visible="true"
SortExpression="deptID">
<itemtemplate>
<%#DataBinder.Eval(Container.DataItem, "deptID")  %>
</itemtemplate>
<edititemtemplate>
<%#DataBinder.Eval(Container.DataItem,"deptID") %>
</edititemtemplate>
</asp:templatecolumn>
<asp:TemplateColumn HeaderText="Name"  SortExpression="deptName"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptName")  %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox text='<%# DataBinder.Eval(Container.DataItem,
"deptName") %>' id="deptName" runat="Server" cssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="Name"
Visible="true" ControlToValidate="deptName" Enabled="true"
ErrorMessage="Required"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</EditItemTemplate>
<footertemplate><asp:textbox id="_deptName" runat="server"
CssClass="Text" />
<asp:requiredfieldvalidator runat="server" id="_Name"
ControlToValidate="_deptName" Error="Fill in a name" Enabled="true"
Display="Dynamic">Required</asp:requiredfieldvalidator>
</footertemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Note"  SortExpression="deptNote"
Visible="True">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "deptNote") %>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox cssClass="Text" text='<%#
DataBinder.Eval(Container.DataItem, "deptNote") %>' id="deptNote"
runat="server" />
</EditItemTemplate>
<footertemplate>
<asp:textbox id="_deptNote" runat="server"[/QUOTE] CssClass="Text"
/>[QUOTE]
</footertemplate>
</asp:TemplateColumn>
<asp:templatecolumn HeaderText="Edit">
<itemtemplate><asp:button CssClass="Text" CommandName="edit"
runat="server"  CausesValidation="false" ID="edit"
Text="Edit"/> <asp:button CssClass="Text" CommandName="delete"
runat="server" ID="delete" Text="Delete" /></itemtemplate>
<edititemtemplate><asp:button CssClass="Text" CommandName="update"
runat="server" CausesValidation="true" ID="update" Text="Save"
/> <asp:button CssClass="Text" CommandName="cancel" runat="server"
CausesValidation="false" ID="cancel"[/QUOTE] [QUOTE="Text="Cancel"/>"]
<footertemplate><asp:button CssClass="Text" Commandname = "Insert"
runat="server" ID="add" Text="Add" /></footertemplate>
</asp:templatecolumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>



--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
 

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,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top