Sunday 15 June 2014

c# - Manually binding data to Gridview -


I need to pack my SQL field in my gridview column. I did this a while ago and it did a great job But I forgot how to do this, then I go to the ASP.NET AutoGenerate column and it works now I want to control data binding, behind my code and my GridView. Any help will be appreciated

  protected zero Page_Load (object sender, EventArgs e) {SqlConnection Conn = New SqlConnection (Sitecore.Configuration.Settings.GetConnectionString ("Feedback")). SqlCommand CMD = New SqlCommand ("select * from fb_results', conn); dataset ds = new dataset (); sqlDataAdapter da = new SqlDataAdapter (cmd); da.Fill (DS); GridView1.DataSource = DS; GridView1.DataBind (); Conn.Close ();}   

GridView:

  top ID = "head1" runat = "server" & gt; & Lt; title & gt; Feedback & lt; / title & gt; & lt; / head & gt; & lt; ASP: Gridview id = "Gridview 1" runat = "server" Autogrentech column = "Fotal" Gt; & lt; column & gt; & lt; ap: boundfield datfilled = "rtp_login" header text = "user id" /> & lt; ap: Groundfilled Datfilled = "FB_URL" headtext = "url ___" /> gt; asp: BoundField DataField = "fb_response" headerText = "Answer: Do you find what you were looking for?" / & Gt; & lt; ASP: Boundfield datedfield = "FB_NRPS" headertext = "no response or no note" />  & lt; asp: Boundfield Dated Field = "fb_serviceCall" HeaderText = "Restricted Service Call" / & gt; & Lt; ASP: BoundfieldDefined = "FB_APRShip" headtext = "Restricted Parts Shipment" / & gt; & Lt; ASP: BoundfieldDefined = "FB_Warny" header = "under warranty" /> & Lt; ASP: BoundfieldDefined = "FB Cankle" Header Text = "Canceled" /> & Lt; ASP: BoundfieldDIFF field = "FB_On" header text = "none above" /> & Lt; / Column & gt; & Lt; / ASP: GridView & gt;    

OK, so regarding comments:

My personal experience is that I had a SQL query that returned it:

  | --------------------------------------------- | | Column1 Column2. Column 3 | --------------- | --------------- | --------------- | | "C1foor1bar" | "C2foor1bar" | "C3foor1bar" | | "C1foor2bar" ​​| "C2foor2bar" ​​| "C3foor2bar" ​​| | "C1foor3bar" | "C2foor3bar" | "C3foor3bar" | | --------------- | --------------- | --------------- |   

My aspx page looked like this:

  & lt; ASP: GridView runat = "server" id = "GridView1" AutoGenerateColumns = "false" & gt; & Lt; ASP: Boundfield Runat = "Server" Datafield = "Struffst" & gt; & Lt; / Asp: boundfield & gt; & Lt; ASP: Boundfield runat = "server" datafield = "string" & gt; & Lt; / Asp: boundfield & gt; & Lt; / ASP: GridView & gt;   

And my pageload looked like this:

  Protected Zero Page_Load (Object Sender, EventArgs e) {SqlConnection Conn = New SqlConnection (& lt; info & Gt;); SQL Commmd CMD = New SQL Commands ("Choose from FB_Rates", Kon); Datatable dt = new datatable (); SqlDataAdapter da = New SqlDataAdapter (cmd); Da.Fill (DT); GridView1.DataSource = dt; GridView1.DataBind (); Conn.Close (); }   

There were two problems first, my column was not said the same. I could easily change them, but in reality they used to represent different figures, so I did not want to do this. Second, I was bringing a lot of data to my reconstruction table for reconstruction:

  Protected Zero Page_Load (Object Sender, EventArgs e) {SqlConnection Conn = New SqlConnection (& lt; Information & gt;); SQL Commmd CMD = New SQL Commands ("Choose from FB_Rates", Kon); Datatable dt = new datatable (); SqlDataAdapter da = New SqlDataAdapter (cmd); Da.Fill (DT); DataTable newTable = createDataTableTemplate (); Foreign currency (Datarov DR in DT.RO) {Datarave Nrv = NewTable. NEWRoW (); New line ["struffst"] = some operations (string) dr ["column 1"]); NewRow ["strLast"] = Some other operations (string) DR ["column 2"]); NewTable.Rows.Add (newRow); } GridView1.DataSource = newTable; GridView1.DataBind (); Conn.Close (); } Private datatable createDataTableTemplate () {DataTable table = new datatable ("table title"); Data column call 1 = new data column ("strststst"); Col1.DataType = System.Type.GetType ("System.String"); Data column call 2 = new data column ("strlust"); Col2.DataType = System.Type.GetType ("System.String"); Table Columns Add (Call 1); Table. Add columns. (Plus 2); Return table; }   

Please note: DataSet is not used, and all boundfields s in runat = "server " of them.

No comments:

Post a Comment