Good day Kpyap. Very sorry for this late reply owing to other things. I make use of the 'EmptyDataTemplate' by the following test but I don't know why I don't have the Add, Edit buttons for the GV. Any advice?
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="temp.aspx.cs" Inherits="NewSite.WebForm1" %>
From your code, I don't see an Add button is define. Edit and Delete button will only shown if there is data.
Please let me know, is your datasource has any data?
Notes : It is always good practice to have well-form tag to eliminate unexpected display layout. The page may be able to run, but don't know is it display as what you want.
Many many thanks Kpyap. Good day, I have these temp records in the table.
create table t (rec_id int identity, fld datetime);
insert into t (fld) values (CONVERT(datetime,'21-11-2009',105));
insert into t (fld) values (CONVERT(datetime,'24-11-2009',105));
insert into t (fld) values (CONVERT(datetime,'01-12-2009',105));
insert into t (fld) values (CONVERT(datetime,'02-12-2009',105));
There're now some records in the table, but I still do not have the corr. buttons from the gridview.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="temp.aspx.cs" Inherits="NewSite.WebForm1" %>
Thanks Kpyap. I can call this page but the records are still not shown. I am progressing with my project. Many thanks for your care and great help every time!
kpyap
Contributor
5212 Points
989 Posts
Re: Onrowcreated
Nov 06, 2009 05:32 AM|LINK
Hi,
I think is possible, build a table layout.
It is free-style in EmptyDataTemplate. You can create anything you want.
wmec
Contributor
6195 Points
3214 Posts
Re: Onrowcreated
Nov 30, 2009 06:13 AM|LINK
Good day Kpyap. Very sorry for this late reply owing to other things. I make use of the 'EmptyDataTemplate' by the following test but I don't know why I don't have the Add, Edit buttons for the GV. Any advice?
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="temp.aspx.cs" Inherits="NewSite.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>temp</title>
</head>
<body>
<form id="form1" runat="server" BackColor="AntiqueWhite" >
<asp:GridView ID="gv3" runat="server"
AutoGenerateColumns="false"
HeaderStyle-BorderStyle="Double"
BorderWidth="2px"
Onrowupdating="gv_edit"
Onrowdeleting="gv_del"
OnRowCommand="gv_ins"
Font-Size="Small"
ForeColor="DarkBlue"
BackColor="AntiqueWhite"
BorderStyle="Groove"
AllowSorting="True"
title="My records"
DataKeyNames="rec_id"
DataSourceID="ds_det" >
<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>
<Columns>
<asp:BoundField DataField="rec_id" HeaderText="Rec ID" HtmlEncode="False" >
<HeaderStyle HorizontalAlign="Left" width="65px" />
<ItemStyle HorizontalAlign="Left" width="65px" />
</asp:BoundField>
<asp:CommandField ShowInsertButton="false" ShowEditButton="true" ShowDeleteButton="true" />
<asp:TemplateField HeaderText="Rec ID" HeaderStyle-HorizontalAlign="Left" >
<ItemTemplate>
<asp:TextBox runat="server" ID="itm_fld" HtmlEncode="False" ForeColor="DarkBlue" BackColor="AntiqueWhite" BorderStyle="None"
ReadOnly="true" Width="65px" Text='<%# Eval("fld") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="edi_fld" HtmlEncode="False"
Enabled="true" Width="65px" Text='<%# Eval("fld") %>' />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="nw_fld" HtmlEncode="False"
Enabled="true" Width="65px" Text='<%# Eval("fld") %>' />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
rec<asp:TextBox runat="server" ID="nwrec" />
fld<asp:TextBox runat="server" ID="nwfld" />
</EmptyDataTemplate>
</asp:GridView>
<html
<asp:SqlDataSource
ID="ds_det" Runat="server"
SelectCommand="select rec_id rec,CONVERT(varchar,fld,105) fld from t where rec_id=@rec_id order by convert(varchar,fld,102)"
UpdateCommand="update t set fld=CONVERT(datetime,@fld,105) where rec_id=@rec_id"
InsertCommand="insert into t(rec_id,fld) values (@rec,CONVERT(datetime,@fld,105))"
ConnectionString="<%$ ConnectionStrings:Mssqlconn %>"
ProviderName="System.Data.SqlClient" >
<SelectParameters>
<asp:SessionParameter Name="rec_id" SessionField="sv_recid2" Type="Int32" Direction="Input" DefaultValue="0"/>
</SelectParameters>
<UpdateParameters>
<asp:SessionParameter Name="rec_id" SessionField="sv_rec" Type="String" Direction="Input" DefaultValue=" "/>
<asp:SessionParameter Name="fld" SessionField="sv_fld" Type="String" Direction="Input" DefaultValue=" "/>
</UpdateParameters>
<InsertParameters>
<asp:SessionParameter Name="rec_id" SessionField="sv_rec" Type="String" Direction="Input" DefaultValue=" "/>
<asp:SessionParameter Name="fld" SessionField="sv_fld" Type="String" Direction="Input" DefaultValue=" "/>
</InsertParameters>
</asp:SqlDataSource>
<div>
</div>
</form>
</body>
</html>
HuaMin Chen
wmec
Contributor
6195 Points
3214 Posts
Re: Onrowcreated
Dec 01, 2009 07:05 AM|LINK
Any advice?
HuaMin Chen
kpyap
Contributor
5212 Points
989 Posts
Re: Onrowcreated
Dec 01, 2009 08:39 AM|LINK
Hi,
Quick look at your code posted, <htm tag is not well-formed.
Please note that EmptyDataTemplate is shown only if there is no data.
wmec
Contributor
6195 Points
3214 Posts
Re: Onrowcreated
Dec 01, 2009 08:54 AM|LINK
Many many thanks Kpyap. But if I am able to run this form then there should be no problem for the tags. Any advice for my previous questions?
HuaMin Chen
kpyap
Contributor
5212 Points
989 Posts
Re: Onrowcreated
Dec 02, 2009 12:20 AM|LINK
Hi,
From your code, I don't see an Add button is define. Edit and Delete button will only shown if there is data.
Please let me know, is your datasource has any data?
Notes :
It is always good practice to have well-form tag to eliminate unexpected display layout. The page may be able to run, but don't know is it display as what you want.
Hope it help.
wmec
Contributor
6195 Points
3214 Posts
Re: Onrowcreated
Dec 02, 2009 01:49 AM|LINK
Many many thanks Kpyap. Good day, I have these temp records in the table.
create table t (rec_id int identity, fld datetime);
insert into t (fld) values (CONVERT(datetime,'21-11-2009',105));
insert into t (fld) values (CONVERT(datetime,'24-11-2009',105));
insert into t (fld) values (CONVERT(datetime,'01-12-2009',105));
insert into t (fld) values (CONVERT(datetime,'02-12-2009',105));
There're now some records in the table, but I still do not have the corr. buttons from the gridview.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="temp.aspx.cs" Inherits="NewSite.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>temp</title>
</head>
<body>
<form id="form1" runat="server" BackColor="AntiqueWhite" >
<asp:GridView ID="gv3" runat="server"
AutoGenerateColumns="false"
HeaderStyle-BorderStyle="Double"
BorderWidth="2px"
Onrowupdating="gv_edit"
Onrowdeleting="gv_del"
OnRowCommand="gv_ins"
Font-Size="Small"
ForeColor="DarkBlue"
BackColor="AntiqueWhite"
BorderStyle="Groove"
AllowSorting="True"
title="My records"
DataKeyNames="rec_id"
DataSourceID="ds_det" >
<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>
<Columns>
<asp:BoundField DataField="rec_id" HeaderText="Rec ID" HtmlEncode="False" >
<HeaderStyle HorizontalAlign="Left" width="65px" />
<ItemStyle HorizontalAlign="Left" width="65px" />
</asp:BoundField>
<asp:CommandField ShowInsertButton="true" ShowEditButton="true" ShowDeleteButton="true" />
<asp:TemplateField HeaderText="Rec ID" HeaderStyle-HorizontalAlign="Left" >
<ItemTemplate>
<asp:TextBox runat="server" ID="itm_fld" HtmlEncode="False" ForeColor="DarkBlue" BackColor="AntiqueWhite" BorderStyle="None"
ReadOnly="true" Width="65px" Text='<%# Eval("fld") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="edi_fld" HtmlEncode="False"
Enabled="true" Width="65px" Text='<%# Eval("fld") %>' />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="nw_fld" HtmlEncode="False"
Enabled="true" Width="65px" Text='<%# Eval("fld") %>' />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
rec<asp:TextBox runat="server" ID="nwrec" />
fld<asp:TextBox runat="server" ID="nwfld" />
</EmptyDataTemplate>
</asp:GridView>
<html
<asp:SqlDataSource
ID="ds_det" Runat="server"
SelectCommand="select rec_id rec,CONVERT(varchar,fld,105) fld from t where rec_id=@rec_id order by convert(varchar,fld,102)"
UpdateCommand="update t set fld=CONVERT(datetime,@fld,105) where rec_id=@rec_id"
InsertCommand="insert into t(rec_id,fld) values (@rec,CONVERT(datetime,@fld,105))"
ConnectionString="<%$ ConnectionStrings:Mssqlconn %>"
ProviderName="System.Data.SqlClient" >
<SelectParameters>
<asp:SessionParameter Name="rec_id" SessionField="sv_recid2" Type="Int32" Direction="Input" DefaultValue="0"/>
</SelectParameters>
<UpdateParameters>
<asp:SessionParameter Name="rec_id" SessionField="sv_rec" Type="String" Direction="Input" DefaultValue=" "/>
<asp:SessionParameter Name="fld" SessionField="sv_fld" Type="String" Direction="Input" DefaultValue=" "/>
</UpdateParameters>
<InsertParameters>
<asp:SessionParameter Name="rec_id" SessionField="sv_rec" Type="String" Direction="Input" DefaultValue=" "/>
<asp:SessionParameter Name="fld" SessionField="sv_fld" Type="String" Direction="Input" DefaultValue=" "/>
</InsertParameters>
</asp:SqlDataSource>
<div>
</div>
</form>
</body>
</html>
HuaMin Chen
kpyap
Contributor
5212 Points
989 Posts
Re: Onrowcreated
Dec 02, 2009 01:59 AM|LINK
Hi,
Please make a well-formed HTML tag.
Is GridView display with records?
Do you build your website with success?
wmec
Contributor
6195 Points
3214 Posts
Re: Onrowcreated
Dec 02, 2009 02:16 AM|LINK
Thanks Kpyap. I can call this page but the records are still not shown. I am progressing with my project. Many thanks for your care and great help every time!
HuaMin Chen
wmec
Contributor
6195 Points
3214 Posts
Re: Onrowcreated
Dec 02, 2009 07:31 AM|LINK
Kpyap, great appreciations to your forever help! Currently I got stuck by this emptytemplate problem!
HuaMin Chen