.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 23rd, 2012, 09:05 AM
mrmagd mrmagd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 1 mrmagd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m
Reputation Power: 0
How I can binding to data

How I can binding to data sources that implement IList, BindingList or IListSource interface via Grid.DataSource property

Reply With Quote
  #2  
Old December 13th, 2013, 03:04 AM
xiaoyuandlg xiaoyuandlg is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2013
Posts: 2 xiaoyuandlg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m 44 sec
Reputation Power: 0
Data binding in grid is always full of problems. BindingList is a generic list type, this control tutorial codes may offer you some insights:

Code:
public class MyObject
{
    public MyObject(int myInt, string myString)
    {
        _myInt = myInt;
        _myString = myString;
    }
    private int _myInt;
    public int MyInt
    {
        get { return _myInt; }
        set { _myInt = value; }
    }
    private string _myString;
    public string MyString
    {
        get { return _myString; }
        set { _myString = value; }
    }
}

Reply With Quote
  #3  
Old January 24th, 2015, 03:12 AM
sriibalaji sriibalaji is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2015
Posts: 2 sriibalaji User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 58 sec
Reputation Power: 0
That's always a good idea to bind inside the generic type..the above code is useful for solving this problem

Reply With Quote
  #4  
Old July 30th, 2015, 06:17 AM
kaybeebaba kaybeebaba is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2015
Posts: 3 kaybeebaba User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by mrmagd
How I can binding to data sources that implement IList, BindingList or IListSource interface via Grid.DataSource property




you can try this code hope it will help

Try
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Dim adp As New OdbcDataAdapter("select * from tablename where names like'%" & TextBox1.Text & "%'", con)
Dim dr As DataRow
Dim dt As DataTable
Dim ds As New DataSet
adp.Fill(ds)
dt = ds.Tables(0)
For Each dr In dt.Rows

Me.dg1.DataSource = dt
Next
con.Close()
grdformat()
Catch ex As Exception
MsgBox(ex.Message)
End Try

Reply With Quote
  #5  
Old July 30th, 2015, 06:20 AM
kaybeebaba kaybeebaba is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2015
Posts: 3 kaybeebaba User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by kaybeebaba
you can try this code hope it will help

Try
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Dim adp As New OdbcDataAdapter("select * from tablename where names like'%" & TextBox1.Text & "%'", con)
Dim dr As DataRow
Dim dt As DataTable
Dim ds As New DataSet
adp.Fill(ds)
dt = ds.Tables(0)
For Each dr In dt.Rows

Me.dg1.DataSource = dt
Next
con.Close()
grdformat()
Catch ex As Exception
MsgBox(ex.Message)
End Try



this is another method, but with this method you need to add column to the datagrid at the desiging time

Try
sqL = "Select StaffID, LastName, FirstName, MI FROM STAFF WHERE LASTNAME LIKE'" & TextBox1.Text & "%' Order by LastName"
con.Open()
Dim cmd As odbcCommand = New odbcCommand(sqL, con)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dgw.Rows.Clear()
Do While dr.Read = True
dgw.Rows.Add(dr(0), dr(1), dr(2), dr(3))
Loop
Catch ex As Exception
MsgBox(ex.Message)
Finally
'cmd.Dispose()
con.Close()
End Try

Reply With Quote
  #6  
Old September 5th, 2015, 01:39 AM
ranjitha21 ranjitha21 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2015
Location: Chennai
Posts: 1 ranjitha21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 16 sec
Reputation Power: 0
Try
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Dim adp As New OdbcDataAdapter("select * from tablename where names like'%" & TextBox1.Text & "%'", con)
Dim dr As DataRow
Dim dt As DataTable
Dim ds As New DataSet
adp.Fill(ds)
dt = ds.Tables(0)
For Each dr In dt.Rows

Me.dg1.DataSource = dt
Next
con.Close()
grdformat()
Catch ex As Exception
MsgBox(ex.Message)
End Try

Reply With Quote
  #7  
Old January 13th, 2016, 07:23 AM
MorinT MorinT is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2015
Location: San Jose, CA
Posts: 7 MorinT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 44 m 50 sec
Reputation Power: 0
Red face Example for binding data.

It is an example of binding data with BindGridview.
I hope it is useful to you.


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
protected void BindGridview()
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("Data Source=Suresh;Integrated Security=true;Initial Catalog=MySampleDB"))
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from productinfo", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
con.Close();
gvDetails.DataSource = ds;
gvDetails.DataBind();
}
}
protected void gvDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvDetails.PageIndex = e.NewPageIndex;
BindGridview();
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > How I can binding to data


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap