srihariacha
November 30th, 2008, 12:27 PM
I need your help to write Add, Edit and Delete features. Here is the functionality details of the project:
1) SelectAll, ClearAll, Add, Edit and Delete is placed under FooterTemplate,
2) Textboxes for Name and Description is placed in FooterTemplate but its visible property is set to false, it has to be visible only if the Add button is clicked and SelectAll, ClearAll, Edit and Delete should become invisible
3) The edit and delete functionality should be enabled when any of the check box is selected and appropriate button is clicked
and the ASP Code is :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-family: Tahoma; font-size: smaller">
<script type="text/javascript">
function Sel()
{
var frm = document.forms[0];
for(i=0;i<frm.length;i++)
{
frm.elements[i].checked=true;
}
}
function DeSel()
{
var frm = document.forms[0];
for(i=0;i<frm.length;i++)
{
frm.elements[i].checked=false;
}
}
</script>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="Crimson" GridLines="None"
AutoGenerateColumns="False" BorderColor="Crimson" BorderStyle="Dashed" BorderWidth="2px"
ShowFooter="True" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand"
OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowCreated="GridView1_RowCreated"
OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="S. No.">
<ItemTemplate>
<asp:Label ID="Check" runat="server" Text='<%# Bind("sno") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="SelectAll" Text="Select All" runat="server" ForeColor="White"></asp:LinkButton>
<asp:TextBox ID="nametb" runat="server" Visible=false></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ename" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="ClearAll" Text="Clear All" runat="server" ForeColor="White"></asp:LinkButton>
<asp:TextBox ID="Desctb" runat="server" Visible=false></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Bind("Description") %>' Width="300"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edesc" runat="server" Text='<%#Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="Add" runat="server" Text="Add" Width="50" Font-Names="Tahoma" CommandName="add" />
<asp:Button ID="Edit" runat="server" Text="Edit" Width="50" Font-Names="Tahoma" CommandName="edit" />
<asp:Button ID="Delete" runat="server" Text="Delete" Width="50" Font-Names="Tahoma"
CommandName="delete" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="SelectRow" runat="Server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="Crimson" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" ForeColor="Crimson" BorderColor="Crimson" BorderWidth="2px" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFFFC0" Font-Bold="True" ForeColor="Crimson" />
<HeaderStyle BackColor="Crimson" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#FFE5E5" BorderColor="#FFCCCC" ForeColor="Crimson" />
</asp:GridView>
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>
My requirement is not to use SQLDataSource rather Data through code.
The ideal output of the GridView looks like this : http://picasaweb.google.co.in/srihariacha/GirdView
Kindly help me !
Regards,
Sri Hari Acha
1) SelectAll, ClearAll, Add, Edit and Delete is placed under FooterTemplate,
2) Textboxes for Name and Description is placed in FooterTemplate but its visible property is set to false, it has to be visible only if the Add button is clicked and SelectAll, ClearAll, Edit and Delete should become invisible
3) The edit and delete functionality should be enabled when any of the check box is selected and appropriate button is clicked
and the ASP Code is :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-family: Tahoma; font-size: smaller">
<script type="text/javascript">
function Sel()
{
var frm = document.forms[0];
for(i=0;i<frm.length;i++)
{
frm.elements[i].checked=true;
}
}
function DeSel()
{
var frm = document.forms[0];
for(i=0;i<frm.length;i++)
{
frm.elements[i].checked=false;
}
}
</script>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="Crimson" GridLines="None"
AutoGenerateColumns="False" BorderColor="Crimson" BorderStyle="Dashed" BorderWidth="2px"
ShowFooter="True" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand"
OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowCreated="GridView1_RowCreated"
OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="S. No.">
<ItemTemplate>
<asp:Label ID="Check" runat="server" Text='<%# Bind("sno") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="SelectAll" Text="Select All" runat="server" ForeColor="White"></asp:LinkButton>
<asp:TextBox ID="nametb" runat="server" Visible=false></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="ename" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="ClearAll" Text="Clear All" runat="server" ForeColor="White"></asp:LinkButton>
<asp:TextBox ID="Desctb" runat="server" Visible=false></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Bind("Description") %>' Width="300"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edesc" runat="server" Text='<%#Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="Add" runat="server" Text="Add" Width="50" Font-Names="Tahoma" CommandName="add" />
<asp:Button ID="Edit" runat="server" Text="Edit" Width="50" Font-Names="Tahoma" CommandName="edit" />
<asp:Button ID="Delete" runat="server" Text="Delete" Width="50" Font-Names="Tahoma"
CommandName="delete" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="SelectRow" runat="Server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="Crimson" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" ForeColor="Crimson" BorderColor="Crimson" BorderWidth="2px" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFFFC0" Font-Bold="True" ForeColor="Crimson" />
<HeaderStyle BackColor="Crimson" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#FFE5E5" BorderColor="#FFCCCC" ForeColor="Crimson" />
</asp:GridView>
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>
My requirement is not to use SQLDataSource rather Data through code.
The ideal output of the GridView looks like this : http://picasaweb.google.co.in/srihariacha/GirdView
Kindly help me !
Regards,
Sri Hari Acha