Forms Data Controls :: GridView And Swap The Datasource
Feb 10, 2010
I have a GridView and can swap the datasource just fine with code. However, The GridView also has a TemplateField with a dropdown connected to a different datasource. How can I swap that one with code too? I don't see how to drill down to find it. I've found stuff on line about accessing the TemplateFields with code, but it seemed to complex for the simple task I am trying to do.
Obviously I am using the tableDnD() function to do that, but after I swapped them, I am saving the datagrid in a DataTable as it is (altered). However this doesn't happen. I need the changes to be posted back to the server. I tried to __doPostBack() after the onDrop function with no luck.
I have one dropdownlist with 10 items and one button.(Item name starts from index 0). It i select one item in dropdownlist and click on Button. The selected item should come to first. How do i do that?
How to swap ddl's selected value on buton click.E.g User has Selected One from ddl1 and three from ddl2 then when the user clicks the Button the values should be swapped.
If I write the following code, teh gridview will no longer show the data
gridview.DataSource = null; gridview.Databound.
My question is , I want to make the same thing with a user control that contain a gridview. when I use the user control in an aspx page, I am able to populate it with data, but when I try to make this code, the Datasource does not show, instead, I see .DV. So I tried this code but then , I do not see DataSource property instead I see DV (DataView), when I put .DV = null, I get an error message that the object is not in existed. any idea how to clear the user control gridview from its data.
im using an excel file as a datasource for my gridview...i can pull all the data into the gridview fine. i am now hoping to allow the user to update the data in the excel file through the gridview. is it possible to update the excel file in this format i.e. allow the user the read/update the excel file as if its a database. i see some references in google that its not possible to update the excel file as the writeout causes problems. does anyone have this working...or should i look into trying to use another datasource.
i was hoping to use an excel file as the app is on a shared server and it would be handy just to have the excel file in the app folder as there is not much data involved.
I have read many, many articles about this issue and still cannot fix my gridview. It is a simple datagrid with a couple readonly fields and then one field is available for edit. I cannot get the new value the user enters into the grid for update... My grid can delete and cancel. I am dynamically binding and know that I have to handle this but I cannot get teh changed quanitity value out of the grid.
This is what is failing...
'The value that changed is blank but I can see the read only values here!! hfQuantity.Value = gvCart.Rows(e.RowIndex).Cells(2).Text.ToString()
Private Sub gvCart_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvCart.RowEditing gvCart.EditIndex = e.NewEditIndex gvCart.DataSource = Session("CartTable") gvCart.DataBind() End Sub Private Sub gvCart_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvCart.RowUpdating 'Find the row that was clicked for updating. Dim row As GridViewRow = gvCart.Rows(e.RowIndex) 'Change the edit index to -1 gvCart.EditIndex = -1 If row IsNot Nothing Then 'The value that changed is blank but I can see the read only values here!! hfQuantity.Value = gvCart.Rows(e.RowIndex).Cells(2).Text.ToString() Dim myDatatable As New DataTable 'Find the Control in the grid. myDatatable = Session("cartTable") For i As Integer = 0 To myDatatable.Rows.Count - 1 If e.RowIndex = i Then myDatatable.Rows(i)(2) = hfQuantity.Value Session("cartTable") = myDatatable gvCart.DataSource = Session("CartTable") gvCart.DataBind() End If Next End If End Sub
I have an object datasource which is using Business object as a myconnection
The method i have defined under myconnection is
Publicstatic DataTable getfn(String dtype, String did, String dprefix, String dname) { datable table = new datatable(); then declared stored proceedure and defined parameters and assighned values
In the stored proceedure it has a query like select column1,coloumn2,coloumn3 As Call from table where I need to take data from Call and display it to the gridview through object datasource .
I am trying to return a dataset. I must be doing something wrong. The returned dataset in this sample code indicates there is a datatable, Users, but there are no datarows. What am I doing wrong? This example is only using the rows.count, but of course I really need to use the whole datatable as the datasource for a gridview.
[Code]....
Public Function getmyds() As DataSet Dim dsUser1 As DataSet = New DataSet() Dim tbUser1 As DataTable = dsUser1.Tables.Add("Users") tbUser1.Columns.Add("UserName") tbUser1.Columns.Add("Days Remaining") tbUser1.Columns.Add("UserAccountControl") Dim rwDefaultUser1 As DataRow = tbUser1.NewRow() rwDefaultUser1("UserName") = "John Smith" rwDefaultUser1("Days remaining") = 100 rwDefaultUser1("userAccountControl") = "Enabled" Return dsUser1 End Function
I am making shopping cart application.On Viewing Shopping Cart,when i try to update the quatity of product column it permit me to edit but wn i click update link.the gridview disappears wid all products.send me some code snippet in C# as i want only quantity column to be editable.I am using the following code:in Code behind File
I have a Dropdownlist in an itemTemplate in a gridview. My gridView binds to dataTable1 (from which the selected value for dropdown comes from) and dropDown binds to dataTable2 (i need to get DataValueField and DataTextField from here).
I have a GridView inside an UpdatePanel in which there is a TemplateField column. I need to save the value of this column every time a user changes it. The problem is that when the TextChanged event causes a postback, the GridView datasource is set to nothing. I've noticed that this happens every time there's a postback. Why?
In asp I want to add row to my gridview when I read barcode. But when I want to add second row , gridview.datasource = null. So, my first row is removed from gridview in TxtBxBarcode_TextChanged event.
TxtBxBarcode and gridview are in the different update panels.
How can I prevent this "gridview.datasource is null when Postback" ?
I have 4 gridviews on a page that get databound with a datatable from sql. So I have created the sort/paging events for each. These were working fine. However now they do not work.
I have a query that joins two tables (in Linq) so I usethe result as an Iqueryable. I want the Query result to be displayed in a gridview, but for some reason I see nothing on the gridview.(I also tried without the join and just using the IQueryable result -and still nothing)
[Code]....
why is doesn't work, or link me to an examlple that is similar - (Also is there another way to use the result of a "join" not as IQueryable)
I have a Gridview that has Paging enabled, and I need to loop through all the rows of the data. Therefore, I assume I need to loop through the datasource instead of through the Gridview.
I change the datasource of my gridview at various times when running.
How can I get a DataView of the GridView's current DataSource, so that I can loop through it?
Something like:
Dim dv as DataView = DirectCast(GridView1.DataSource, DataView)
except that this comes back as Nothing, probably because a Datasource isn't a dataview.
Problem: it will sort and paging correctly but when after change a page, it will not display the corrected sorted order.
Protected Sub PFTGridView_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles PFTGridView.PageIndexChanging Dim PFTObj As New PFT Dim PFTDST As New Data.DataSet