Brajesh Singh

Brajesh Singh

  • NA
  • 10
  • 1.4k

some body help me

May 4 2017 1:46 PM
 
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Name</td>
<td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Age</td>
<td>
<asp:TextBox ID="txtage" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="savebtn" runat="server" Text="Save" OnClick="savebtn_Click" />
</td>
</tr>
<tr>
<asp:GridView ID="grd" runat="server" AutoGenerateColumns="false" OnRowCommand="grd_RowCommand" >
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%#Eval("Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Age">
<ItemTemplate>
<%#Eval("age") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="editbtn" runat="server" Text="Edit" CommandName="edit" CommandArgument='<%#Eval("ID") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Deletebtn" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%#Eval("ID")%>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</tr>
</table>
</div>
</form>
</body>
</html>
==================================
student.aspx.cs 
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace class_01
{
public partial class student : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
Fill_grid();
}
public void Fill_grid()
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from student",con);
SqlDataAdapter da =new SqlDataAdapter(cmd);
DataTable dt =new DataTable();
da.Fill(dt);
grd.DataSource=dt;
grd.DataBind();
con.Close();
}
protected void savebtn_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into student(Name,Age) values('" + txtname.Text + "','" + txtage.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
Fill_grid();
}
protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DHOOM3")
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from student", con);
cmd.Parameters.AddWithValue("@id", e.CommandArgument);
cmd.ExecuteNonQuery();
con.Close();
Fill_grid();
}
else if (e.CommandName == "KRISS3")
{
con.Open();
SqlCommand cmd = new SqlCommand(", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", e.CommandArgument);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
txtname.Text = dt.Rows[0][1].ToString();
txtage.Text = dt.Rows[0][3].ToString();
}
}
}
}
============================
Web.config 
 

Answers (8)