473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Data Grid

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.SqlClient;
  8. using System.Configuration;
  9. using System.Data;
  10.  
  11. namespace Final
  12. {
  13.     public partial class Default : System.Web.UI.Page
  14.     {
  15.         SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["App"].ConnectionString);
  16.         protected void Page_Load(object sender, EventArgs e)
  17.         {
  18.             Label7.Visible = true;
  19.             if (IsPostBack == false)
  20.             {
  21.                 if (conn.State == ConnectionState.Closed)
  22.                 {
  23.                     conn.Open();
  24.  
  25.                 }
  26.                 //string strn = "select * from Dtls";
  27.                 //DataSet ds = new DataSet();
  28.  
  29.  
  30.  
  31.                 //SqlDataAdapter da = new SqlDataAdapter(strn, conn);
  32.                 //da.Fill(ds,"tab");
  33.                 //int i = ds.Tables["Tab"].Rows.Count;
  34.                 //if (ds.Tables.Count > 0)
  35.                 //{
  36.                 //    DataGrid1.DataSource = ds;
  37.                 //    DataGrid1.DataBind();
  38.  
  39.                 //}
  40.                 string strn = "select *  from Dtls";
  41.                 DataSet ds = new DataSet();
  42.  
  43.  
  44.  
  45.                 SqlDataAdapter da = new SqlDataAdapter(strn, conn);
  46.                 da.Fill(ds, "tab");
  47.                 int i = ds.Tables["Tab"].Rows.Count;
  48.                 if (ds.Tables.Count > 0)
  49.                 {
  50.                     DropDownList1.DataSource = ds;
  51.                     DropDownList1.DataTextField = "Name";
  52.                   //  DropDownList1.DataValueField = "id";
  53.                     DropDownList1.DataBind();
  54.  
  55.  
  56.  
  57.  
  58.                 }
  59.             }
  60.         }
  61.  
  62.         void clear()
  63.         {
  64.             TextBox1.Text = "";
  65.             TextBox2.Text = "";
  66.             TextBox3.Text = "";
  67.             TextBox4.Text = "";
  68.             TextBox5.Text = "";
  69.             TextBox6.Text = "";
  70.         }
  71.         protected void Button2_Click(object sender, EventArgs e)
  72.         {
  73.  
  74.             if (conn.State == ConnectionState.Closed)
  75.             {
  76.                 conn.Open();
  77.             }
  78.  
  79.              string str = "insert into  dtls values('" + TextBox1.Text + "','" + TextBox2.Text + "',convert(smalldatetime,'" + TextBox3.Text + "',103),'" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "')";
  80.              SqlCommand cmd = new SqlCommand(str, conn);
  81.              cmd.ExecuteNonQuery();
  82.              conn.Close();
  83.              clear();
  84.              Response.Redirect("Default.aspx");
  85.  
  86.         }
  87.  
  88.         protected void Button3_Click(object sender, EventArgs e)
  89.         {
  90.             if (conn.State == ConnectionState.Closed)
  91.             {
  92.                 conn.Open();
  93.             }
  94.             string str = "delete from  dtls where Name= '"+DropDownList1.SelectedItem+ "'";
  95.             SqlCommand cmd = new SqlCommand(str, conn);
  96.             cmd.ExecuteNonQuery();
  97.             conn.Close();
  98.             Response.Redirect("Default.aspx");
  99.  
  100.  
  101.         }
  102.  
  103.         protected void Button6_Click(object sender, EventArgs e)
  104.         {
  105.  
  106.             if (conn.State == ConnectionState.Closed)
  107.             {
  108.                 conn.Open();
  109.             }
  110.             string str = "update Dtls set Name='" + TextBox1.Text + "', Address='" + TextBox2.Text + "'  where Name='" + DropDownList1.SelectedValue + "'";
  111.             SqlCommand cmd = new SqlCommand(str, conn);
  112.             cmd.ExecuteNonQuery();
  113.             conn.Close();
  114.  
  115.         }
  116.  
  117.         protected void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
  118.         {
  119.             if (e.CommandName == "SELECT")
  120.             {
  121.  
  122.                 Label lbl = e.Item.FindControl("Label10") as Label;
  123.                 string sdt = lbl.Text;
  124.                 ViewState["ag"] = sdt;
  125.  
  126.             }
  127.         }
  128.  
  129.         protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  130.         {
  131.             //if (conn.State == ConnectionState.Closed)
  132.             //{
  133.             //    conn.Open();
  134.             //}
  135.             //string str = "Select Name,Address,DOB,Profession,Email,Mob from Dtls where Name='" + DropDownList1.SelectedValue + "' ";
  136.             //DataSet ds = new DataSet();
  137.             //SqlDataAdapter da = new SqlDataAdapter(str, conn);
  138.             //da.Fill(ds, "f1");
  139.             //if (ds.Tables["f1"].Rows.Count > 0)
  140.             //{
  141.             //    TextBox1.Text = ds.Tables["f1"].Rows[0].ItemArray[0].ToString();
  142.             //    //incase kittiyillel ithu kodukkanam 
  143.             //    TextBox1.Text = ds.Tables["f1"].Rows[0].ItemArray.Contains("Name").ToString();
  144.             //    TextBox2.Text = ds.Tables["f1"].Rows[0].ItemArray[1].ToString();
  145.             //    TextBox3.Text = ds.Tables["f1"].Rows[0].ItemArray[2].ToString();
  146.             //    TextBox4.Text = ds.Tables["f1"].Rows[0].ItemArray[3].ToString();
  147.             //    TextBox5.Text = ds.Tables["f1"].Rows[0].ItemArray[3].ToString();
  148.             //    TextBox6.Text = ds.Tables["f1"].Rows[0].ItemArray[3].ToString();
  149.  
  150.             }
  151.  
  152.         protected void TextBox7_TextChanged(object sender, EventArgs e)
  153.         {
  154.             Label7.Visible = false;
  155.             conn.Open();
  156.             SqlCommand cmd = new SqlCommand("select * from Dtls where Name like '%" + TextBox7.Text + "%'", conn);
  157.             SqlDataReader dr; 
  158.             dr = cmd.ExecuteReader();
  159.             while (dr.Read())
  160.             {
  161.               ListBox1.Items.Add(dr["Name"].ToString());
  162.               ListBox1.Visible = true;
  163.             }
  164.             dr.Close();
  165.  
  166.             conn.Close();
  167.         }
  168.  
  169.         protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
  170.         {
  171.  
  172.             TextBox7.Text = ListBox1.SelectedItem.Text;
  173.  
  174.             ListBox1.Visible = false;
  175.  
  176.             ListBox1.Items.Clear();
  177.         }
  178.  
  179.         protected void Button5_Click(object sender, EventArgs e)
  180.         {
  181.  
  182.             Label7.Text = TextBox7.Text;
  183.  
  184.             ListBox1.Visible = true;
  185.         }
  186.  
  187.  
  188.  
  189.  
  190.  
  191.         }
  192.  
  193.       }
Mar 8 '12 #1
1 2114
PsychoCoder
465 Expert Mod 256MB
Ok, now you've posted a butt load of code, so what's the issue you're having? You cant just post a bunch of code and think we're going to know what the issue is.
Mar 8 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jordan O'Hare | last post by:
Hello Everyone, I am after some help with the following: I have a windows application that contains a list box and two data grids. All three controls are binded to a dataset that contains...
5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
3
by: Snake | last post by:
I have a vb .net program which fills a data grid upon form load from an acccess database. This works great. Now, I have to add a combo box and use it to alter the underlying sql statement and...
2
by: Brian Henry | last post by:
Hi, I have a data grid that is set up like this Page items displayed = 10 EnableViewState = false (i dont want to send large amounts of data over the internet!) CustomPaging = false...
1
by: Linda | last post by:
Hi, I'm new to asp.net and tryign to learn how to work with data grids. I'm retrieving data from a stored procedure and putting it in a data grid. I then want to be able to sort the data when...
3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
0
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master)...
2
by: nullref | last post by:
Hello. I am wondering about the ability of the data grid for being able to maintain state of data when paginating. I am trying to figure out if I can use the grid to enable editing of data that...
0
by: zafar | last post by:
I don't know what property should be used for hiding colums in Data Grid, whereas in Data Grid View we have DataGridView1.Colums(index).Visible = False , But how can I hide Colums in Data Grid.....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.