| Name | |
| Age | |
==================================
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

Amit GuptaRank #190 · 12.8K reputationPosted May 4, 2017, 10:45 AM EDT
Raja TRank #685 · 3.5K reputationPosted May 4, 2017, 8:18 PM EDT
Manav PandyaRank #166 · 14.3K reputationPosted May 4, 2017, 8:39 PM EDT
Nigel FernandesRank #753 · 3.1K reputationPosted May 4, 2017, 8:39 PM EDT
Nigel FernandesRank #753 · 3.1K reputationPosted May 4, 2017, 8:48 PM EDT
Karthi KeyanRank #1,926 · 762 reputationPosted May 4, 2017, 9:57 PM EDT
Rafnas T PRank #280 · 8.8K reputationPosted May 4, 2017, 8:44 PM EDT
Rafnas T PRank #280 · 8.8K reputationPosted May 4, 2017, 10:02 PM EDT