<Gridview>
<column>
</column>
<EmptyDataTemplate>
<table>
<tr>
<td><asp:Label ID="Label1" runat="server" Text="Name"></asp:Label></td>
<td><asp:Label ID="Label2" runat="server" Text="Age"></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text="Place"></asp:Label></td>
<td><asp:Label ID="Label4" runat="server" Text="Dob"></asp:Label></td>
<td><asp:Label ID="Label6" runat="server" Text="Add"></asp:Label></td>
</tr>
<tr>
<td><asp:TextBox ID="txtNameE" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtAgeE" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtPlaceE" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtDOBE" runat="server" ></asp:TextBox></td>
<td><asp:ImageButton runat="server" ID="imgAddE" ImageUrl="Images/add.gif" CommandName="InsertEmpty"/></td>
</tr>
</table>
</EmptyDataTemplate>
</Gridview>
-----------------------------------
aspx.cs
protected void gvwtest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
TextBox txtName = gvwtest.FooterRow.FindControl("txtName") as TextBox;
TextBox txtAge = gvwtest.FooterRow.FindControl("txtAge") as TextBox;
TextBox txtPlace = gvwtest.FooterRow.FindControl("txtPlace") as TextBox;
TextBox txtDOB = gvwtest.FooterRow.FindControl("txtDOB") as TextBox;
string query = "INSERT INTO TBL_UserDetails VALUES((SELECT ISNULL(MAX(Id),0) as maxid FROM TBL_UserDetails)+1,'" + txtName.Text + "','" + txtAge.Text + "','" + txtPlace.Text + "','" + txtDOB.Text + "')";
DataConnection(query, 0);
FillUserDetails();
}
else if (e.CommandName == "InsertEmpty")
{
TextBox txtName = gvwtest.Controls[0].Controls[0].FindControl("txtNameE") as TextBox;
TextBox txtAge = gvwtest.Controls[0].Controls[0].FindControl("txtAgeE") as TextBox;
TextBox txtPlace = gvwtest.Controls[0].Controls[0].FindControl("txtPlaceE") as TextBox;
TextBox txtDOB = gvwtest.Controls[0].Controls[0].FindControl("txtDOBE") as TextBox;
string query = "INSERT INTO TBL_UserDetails VALUES((SELECT ISNULL(MAX(Id),0) as maxid FROM TBL_UserDetails)+1,'" + txtName.Text + "','" + txtAge.Text + "','" + txtPlace.Text + "','" + txtDOB.Text + "')";
DataConnection(query, 0);
FillUserDetails();
}
}
<column>
</column>
<EmptyDataTemplate>
<table>
<tr>
<td><asp:Label ID="Label1" runat="server" Text="Name"></asp:Label></td>
<td><asp:Label ID="Label2" runat="server" Text="Age"></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text="Place"></asp:Label></td>
<td><asp:Label ID="Label4" runat="server" Text="Dob"></asp:Label></td>
<td><asp:Label ID="Label6" runat="server" Text="Add"></asp:Label></td>
</tr>
<tr>
<td><asp:TextBox ID="txtNameE" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtAgeE" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtPlaceE" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtDOBE" runat="server" ></asp:TextBox></td>
<td><asp:ImageButton runat="server" ID="imgAddE" ImageUrl="Images/add.gif" CommandName="InsertEmpty"/></td>
</tr>
</table>
</EmptyDataTemplate>
</Gridview>
-----------------------------------
aspx.cs
protected void gvwtest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
TextBox txtName = gvwtest.FooterRow.FindControl("txtName") as TextBox;
TextBox txtAge = gvwtest.FooterRow.FindControl("txtAge") as TextBox;
TextBox txtPlace = gvwtest.FooterRow.FindControl("txtPlace") as TextBox;
TextBox txtDOB = gvwtest.FooterRow.FindControl("txtDOB") as TextBox;
string query = "INSERT INTO TBL_UserDetails VALUES((SELECT ISNULL(MAX(Id),0) as maxid FROM TBL_UserDetails)+1,'" + txtName.Text + "','" + txtAge.Text + "','" + txtPlace.Text + "','" + txtDOB.Text + "')";
DataConnection(query, 0);
FillUserDetails();
}
else if (e.CommandName == "InsertEmpty")
{
TextBox txtName = gvwtest.Controls[0].Controls[0].FindControl("txtNameE") as TextBox;
TextBox txtAge = gvwtest.Controls[0].Controls[0].FindControl("txtAgeE") as TextBox;
TextBox txtPlace = gvwtest.Controls[0].Controls[0].FindControl("txtPlaceE") as TextBox;
TextBox txtDOB = gvwtest.Controls[0].Controls[0].FindControl("txtDOBE") as TextBox;
string query = "INSERT INTO TBL_UserDetails VALUES((SELECT ISNULL(MAX(Id),0) as maxid FROM TBL_UserDetails)+1,'" + txtName.Text + "','" + txtAge.Text + "','" + txtPlace.Text + "','" + txtDOB.Text + "')";
DataConnection(query, 0);
FillUserDetails();
}
}
No comments:
Post a Comment