Asp.Net Gridview :  Bind Database Table

Asp.Net Gridview : Bind Database Table

CodAffection

7 лет назад

238,131 Просмотров

How to Bind Database Table in Asp.Net Gridview

In this video, we have discussed how to bind or display database table in asp.net gridview using SQL Server. In the last column, we have shown a link button to select a row.

📂 GitHub Repository
https://goo.gl/z4nwbc

💖 Buy me a Coffee
https://bit.ly/3L36ut4 (PayPal)
https://bit.ly/3VF0iPT (Razorpay)

🌀 Related Videos
https://goo.gl/oxDoDK : Asp.Net - Insert Update Delete
https://goo.gl/qshuJk : Complete Asp.net Tutorial
https://goo.gl/TUhsm5 : Asp.net Login Page
https://goo.gl/ySUFf8 : Similar Mvc Tutorials
https://goo.gl/3ajHuA : Similar C# Video Tutorials
https://goo.gl/yHZcCo : Build Complete Asp.Net MVC App
https://goo.gl/ZXKqT9 : jQuery Ajax in Asp.net MVC

🔗 Find me in
Udemy : https://bit.ly/3RtyQSB
Facebook : https://www.facebook.com/codaffection
GitHub : https://github.com/codaffection
Discord : https://discord.gg/Nky4YTFEsG
Twitter : https://twitter.com/codaffection

#AspNet #CodAffection

Тэги:

#how_to_display_database_table_in_asp.net_gridview #bind_database_table_in_gridview #table_in_asp.net_gridview #show_c#_datatable_in_asp.net_webform_gridview #asp.net_web_form_tutorial #add_select_link_button_to_gridview_with_command_argument #in_c#_asp.net_gridview #using_sample_project #using_SQL_Server_database #columns_in_asp.net_gridview #boundfield_in_gridview #how_to_connect_gridview_to_sql_database_in_asp.net #asp_gridview_database #asp.net_sql_table #CodAffection
Ссылки и html тэги не поддерживаются


Комментарии:

Vidhya Arumugam
Vidhya Arumugam - 11.09.2023 19:35

Thank for the video ... my job is still there for me bcaz of u people...

Ответить
M K
M K - 31.05.2023 19:44

78 protected void insert()
{
XmlTextReader reader = new XmlTextReader(Server.MapPath("/XMLL/XMLFile1.xml"));
DataSet ds = new DataSet();
ds.ReadXml(reader);
DataView dv = new DataView(ds.Tables[0]);
DataTable dt = dv.Table;
dt.DefaultView.Sort = "citano DESC";
dt = dt.DefaultView.ToTable(true);
reader.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
}
SqlConnection con = new SqlConnection("");
protected void btnPosalji_Click(object sender, EventArgs e)
{
SqlCommand com = new SqlCommand("INSERT INTO table values(@item1, @item2, @item3, @item4)", con);
com.Parameters.AddWithValue("@item1", tb1.Text);
com.Parameters.AddWithValue("@item2", tb2.Text);
com.Parameters.AddWithValue("@item3", tb3.Text);
com.Parameters.AddWithValue("@item4", DateTime.Now.ToShortDateString());
con.Open();
com.ExecuteNonQuery();
}

Ответить
M K
M K - 31.05.2023 19:41

15 public void insert()
{
if (DropDownList1.SelectedIndex > -1)
{
string pathh= Server.MapPath($"~/TXT/{DropDownList1.SelectedValue}.txt");
string[] liness = File.ReadAllLines(putanja);
foreach (string line in liness)
{
if (line.StartsWith("SMER"))
{
string smer = line.Remove(0, 5);
DropDownList2.Items.Add(smer);
} }
} }
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = null;
GridView1.DataBind();
DataSet ds = new DataSet();
ds.Tables.Add(new DataTable());
ds.Tables.Add(new DataTable());
ds.Tables[0].Columns.Add("RBR", typeof(string));
ds.Tables[0].Columns.Add("Polazak", typeof(string));
ds.Tables[1].Columns.Add("RBR", typeof(string));
ds.Tables[1].Columns.Add("Polazak", typeof(string));

if (DropDownList1.SelectedIndex > -1 && DropDownList2.SelectedIndex > -1)
{
string pathh = Server.MapPath($"~/TXT/{DropDownList1.SelectedValue}.txt");
string[] liness = File.ReadAllLines(pathh);
int i = -1, j = 0;
foreach (string line in liness)
{

if (line.StartsWith("SMER"))
{
i++;
j = 0;
}
else
{
j++;
ds.Tables[i].Rows.Add(j, line);
}
}
if (DropDownList2.SelectedIndex == 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
else if (DropDownList2.SelectedIndex == 1)
{
GridView1.DataSource = ds.Tables[1];
GridView1.DataBind();
}
}

Ответить
M K
M K - 31.05.2023 19:39

13 protected void Page_Load(object sender, EventArgs e)
{
table.Columns.Add("1", typeof(int));
table.Columns.Add("2", typeof(string));
table.Columns.Add("3", typeof(string));
table.Columns.Add("3", typeof(string));
table.Columns.Add("4", typeof(string));
table.Columns.Add("5", typeof(string));
table.Columns.Add("6", typeof(string));
string path = Server.MapPath("~/text/people.txt");
string[] dataa = File.ReadAllLines(ppath);
foreach (string p in dataa)
{
string[] kolone = p.Split(';');
table.Rows.Add(kolone);
}
GridView1.DataSource = table;
GridView1.DataBind();
List<string> place = new List<string>();
foreach (string p in dataa)
{
string[] rows = p.Split(';');
place.Add(rows[6]);
}
DropDownList1.Items.Add(new ListItem(String.Empty, "-1"));
foreach (string m in place)
{
ListItem item = new ListItem(m);
if (!DropDownList1.Items.Contains(item))
{
DropDownList1.Items.Add(item);
}
}
}

protected void Button1_Click(object sender, EventArgs e)
{
DataTable temp = table.Copy();
for (int i = 0; i < temp.Rows.Count; i++)
{
if (!temp.Rows[i][1].ToString().Contains(TextBox1.Text) ||
!temp.Rows[i][2].ToString().Contains(TextBox2.Text) ||
!temp.Rows[i][3].ToString().Contains(TextBox3.Text) ||
!temp.Rows[i][4].ToString().Contains(TextBox4.Text) ||
!temp.Rows[i][5].ToString().Contains(TextBox5.Text) ||
!temp.Rows[i][6].ToString().Contains(DropDownList1.SelectedItem.Text))
{
temp.Rows.RemoveAt(i);
i--;
}
}
GridView1.DataSource = temp;
GridView1.DataBind();
}

Ответить
Jancsovics Mark
Jancsovics Mark - 08.03.2023 10:17

Thank you so much! You helped me a lot! 🙂

Ответить
Yosi Kariv
Yosi Kariv - 17.12.2022 19:49

you recommended to do the SQL class you did as a static class so i wont create a instence of the data base every function?

Ответить
Kfir-Mr Pluto
Kfir-Mr Pluto - 19.10.2022 23:10

You are my hero !!!!!!!!!!!!!!!!
🕳💙💣🤏👩👩‍💼👩‍✈💂👸👰‍♂🦹🏇🏃‍♀🧗🦁🐄🌱🌺🍂🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱🌱

Ответить
BunnyGirl
BunnyGirl - 24.08.2022 20:04

thank you so much it solved my biggest problem 1.4K liker congratz

Ответить
Mickey Kutti
Mickey Kutti - 03.06.2022 11:27

I need help

Ответить
Mickey Kutti
Mickey Kutti - 03.06.2022 11:27

Hiii

Ответить
Mickey Kutti
Mickey Kutti - 30.05.2022 15:46

When I click the design button all columns are displaying like databound databound..... What's the error plz help me

Ответить
Fernando Balderas
Fernando Balderas - 15.05.2022 23:28

Thats great!, I have a doubt, how can I assign an ID to the table generated, I would like to add styles on it with JS... Thanks

Ответить
Bartho souza
Bartho souza - 15.04.2022 17:32

Very helpful, nice explanation, thanks a lot

Ответить
Prem Sagar Shukla
Prem Sagar Shukla - 02.10.2021 07:24

Thanks

Ответить
kitsabee
kitsabee - 24.08.2021 21:33

How can I capture this value in the client side javascript?

Ответить
Arumuga selvam
Arumuga selvam - 10.08.2021 12:08

Thank you so much sir

Ответить
grbsql
grbsql - 21.07.2021 17:52

Thank you very much for sharing such excellent work

Ответить
Susmita Hazra
Susmita Hazra - 06.07.2021 20:02

Sir I need a help

Ответить
ANZI MK
ANZI MK - 24.06.2021 17:52

Thankz a alot

Ответить
nima
nima - 17.06.2021 12:57

nice one very helpful.

Ответить
Ubl Web
Ubl Web - 27.05.2021 19:38

Thank you very much! That was very helpful.

Ответить
Ramdev Darak
Ramdev Darak - 28.03.2021 23:51

This helped a lot! Thanks man

Ответить
Jon Telletxea
Jon Telletxea - 14.03.2021 14:04

You are my father! You saved my life! :)

Ответить
Procrastenedor
Procrastenedor - 17.02.2021 04:59

Thank you!

Ответить
Miguel Rivas
Miguel Rivas - 17.11.2020 17:29

You are amazing, thank you for sharing this video!!

Ответить
Engr TURKI
Engr TURKI - 25.10.2020 07:42

👍👍

Ответить
Raj
Raj - 05.07.2020 07:05

This Post may be 3 years back but it helped me. :) Thank you

Ответить
youssef TIKO
youssef TIKO - 11.05.2020 06:16

THAANKS

Ответить
Nick Pawsey
Nick Pawsey - 15.09.2019 02:40

This helped a lot! Thanks man

Ответить
Daniel Riojas
Daniel Riojas - 14.09.2019 17:35

te amo

Ответить
Solanki Disha
Solanki Disha - 09.09.2019 07:53

Thank you so much

Ответить
Joydeep Das
Joydeep Das - 07.05.2019 11:55

Got what i was looking for! Thanks a lot bro :)

Ответить
mglx6
mglx6 - 01.05.2019 00:32

Thanks a lot!! from Chile

Ответить
Fabian Chukwukadibia
Fabian Chukwukadibia - 23.03.2019 12:53

One of the best Online tutorial I have ever seen. Not too great English but the message was crystal clear. Well delivered and Thank you for this.

Ответить
kunal patel
kunal patel - 28.02.2019 14:25

thank you... it helped me...

Ответить
pham anh
pham anh - 25.02.2019 21:34

how a helpful tutorial, many thanks from Vietnam

Ответить
manish kumar
manish kumar - 03.01.2019 10:23

sir how to copy string connectionstring = @"?" from sql database table ?

Ответить
Najar Mahamud
Najar Mahamud - 01.01.2019 04:39

Great Tutorials :-) Tnx

Ответить
Numan Duraklar
Numan Duraklar - 30.12.2018 19:03

Thank you man!!!

Ответить
KENNETH MONTERO PONCE
KENNETH MONTERO PONCE - 15.12.2018 02:33

Very Good, thank you, excellent video.

Ответить
Nassos Kranidiotis
Nassos Kranidiotis - 05.11.2018 13:36

Thank you very much! That was very helpful.

Ответить
Juan Pablo Pereira
Juan Pablo Pereira - 10.08.2018 06:10

Good video , from chile

Ответить