*****************Design************
<form id="form1" runat="server">
<div>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="BE.BELab" DeleteMethod="Deletelab" InsertMethod="insertlab"
SelectMethod="show" TypeName="BLL.LabBLL" UpdateMethod="Updatelab">
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server"
DataSourceID="ObjectDataSource1" DataKeyNames="ID" Height="190px"
ShowFooter="True" AlternatingRowStyle-BackColor="SeaGreen"
HeaderStyle-BackColor="Aqua" AutoGenerateColumns="False"
FooterStyle-BackColor="Azure">
<AlternatingRowStyle BackColor="SeaGreen"></AlternatingRowStyle>
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnadd" runat="server" Text="Add" OnClick="Insert_into_Grid" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" SortExpression="ID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assignment" SortExpression="Assignment">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Assignment") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Assignment") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAssignment" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RollNo" SortExpression="RollNo">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="StdName"
DataValueField="StdRollNo" SelectedValue='<%# Bind("RollNo") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBStudentTestConnectionString %>"
SelectCommand="SELECT [StdName], [StdRollNo] FROM [tblStudent]">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:HiddenField ID="Hd1" runat="server" Value='<%# Bind("RollNo") %>' />
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="StdName"
DataValueField="StdRollNo" SelectedValue='<%# Bind("RollNo") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBStudentTestConnectionString %>"
SelectCommand="SELECT [StdName], [StdRollNo] FROM [tblStudent]">
</asp:SqlDataSource>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="StdName"
DataValueField="StdRollNo" SelectedValue='<%# Bind("RollNo") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBStudentTestConnectionString %>"
SelectCommand="SELECT [StdName], [StdRollNo] FROM [tblStudent]">
</asp:SqlDataSource>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="Azure"></FooterStyle>
<HeaderStyle BackColor="Aqua"></HeaderStyle>
</asp:GridView>
<div>
</div>
</form>
**************************back coding************
protected void Insert_into_Grid(object sender, EventArgs e)
{
Control control = null;
if (GridView1.FooterRow != null)
{
control = GridView1.FooterRow;
}
else
{
control = GridView1.Controls[0].Controls[0];
}
Int32 ID = Convert.ToInt32((control.FindControl("txtID") as TextBox).Text);
string txtAssignment = (control.FindControl("txtAssignment") as TextBox).Text;
string Rollno = (control.FindControl("DropDownList1") as DropDownList).SelectedValue;
BELab be = new BELab();
be.ID = ID;
be.RollNo = Rollno;
be.Assignment = txtAssignment;
new LabBLL().insertlab(be);
GridView1.DataBind();
}
<form id="form1" runat="server">
<div>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="BE.BELab" DeleteMethod="Deletelab" InsertMethod="insertlab"
SelectMethod="show" TypeName="BLL.LabBLL" UpdateMethod="Updatelab">
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server"
DataSourceID="ObjectDataSource1" DataKeyNames="ID" Height="190px"
ShowFooter="True" AlternatingRowStyle-BackColor="SeaGreen"
HeaderStyle-BackColor="Aqua" AutoGenerateColumns="False"
FooterStyle-BackColor="Azure">
<AlternatingRowStyle BackColor="SeaGreen"></AlternatingRowStyle>
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnadd" runat="server" Text="Add" OnClick="Insert_into_Grid" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" SortExpression="ID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assignment" SortExpression="Assignment">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Assignment") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Assignment") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAssignment" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RollNo" SortExpression="RollNo">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="StdName"
DataValueField="StdRollNo" SelectedValue='<%# Bind("RollNo") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBStudentTestConnectionString %>"
SelectCommand="SELECT [StdName], [StdRollNo] FROM [tblStudent]">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:HiddenField ID="Hd1" runat="server" Value='<%# Bind("RollNo") %>' />
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="StdName"
DataValueField="StdRollNo" SelectedValue='<%# Bind("RollNo") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBStudentTestConnectionString %>"
SelectCommand="SELECT [StdName], [StdRollNo] FROM [tblStudent]">
</asp:SqlDataSource>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="StdName"
DataValueField="StdRollNo" SelectedValue='<%# Bind("RollNo") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBStudentTestConnectionString %>"
SelectCommand="SELECT [StdName], [StdRollNo] FROM [tblStudent]">
</asp:SqlDataSource>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="Azure"></FooterStyle>
<HeaderStyle BackColor="Aqua"></HeaderStyle>
</asp:GridView>
<div>
</div>
</form>
**************************back coding************
protected void Insert_into_Grid(object sender, EventArgs e)
{
Control control = null;
if (GridView1.FooterRow != null)
{
control = GridView1.FooterRow;
}
else
{
control = GridView1.Controls[0].Controls[0];
}
Int32 ID = Convert.ToInt32((control.FindControl("txtID") as TextBox).Text);
string txtAssignment = (control.FindControl("txtAssignment") as TextBox).Text;
string Rollno = (control.FindControl("DropDownList1") as DropDownList).SelectedValue;
BELab be = new BELab();
be.ID = ID;
be.RollNo = Rollno;
be.Assignment = txtAssignment;
new LabBLL().insertlab(be);
GridView1.DataBind();
}
No comments:
Post a Comment