.NET Framework - Column count / Access GridView Column after DataBind
Asked By Finn Stampe Mikkelsen
19-Aug-10 08:44 AM

Hi
I have below GridView, which i in codebehind page databind with a dynamicly
created datatable.
This all works fine, but after the databind i still only have a column count
of 1 although the datatable adds another 4 columns to the gridview. This
represents a problem, since i would like to have the last column properties
change on the fly and i cannot access the properties of any column besides
the on definded below. None of the databound columns created by the DataBind
method can be accessed..
How can i access these columns??
/Finn
ForeColor="#333333"
GridLines="None" onrowcommand="UdlaanGrd_RowCommand" >
HeaderText="Fjern Vare" Text="Fjern"
CommandName="Fjern" >
ForeColor="White" />
ForeColor="White" />
HorizontalAlign="Center" />
ForeColor="#333333" />
--
Der er 10 slags mennesker - Dem som forst?r bin?r og dem som ikke g?r.
There are 10 kinds of people. Those who understand binary and those who
do not.
Es gibt 10 Arten von Menschen. Die, die Bin?r verstehen, bzw. die, die es
nicht tuhen.
SqlDataSource
(1)
GridView
(1)
DataBind
(1)
Button
(1)
Column count
(1)
Rajeev Gopal replied to Finn Stampe Mikkelsen
Finn,
If you mention the columns in the GridView (not allowing AutoGenerate
of Columns), then you can get access to the column count. As of now
the grid is aware of only one column and that is of Button.
Hope you got it.
Thanks,
Rajeev
http://rajeevgopal.blogspot.com
Finn Stampe Mikkelsen replied to Rajeev Gopal
Subject: Re: Column count / Access GridView Column after DataBind
Hi
Yeah, well then it is not dynamic and i need to autogenerate the individual
columns..
Funny enough, the individual rows have knowledge of the correct number of
cells, including the one i want to make invisible.. I find it curious, that
i can make individual cells invisible and access them by index, but i cannot
access the whole columns by index...
/Finn
Rajeev Gopal replied to Finn Stampe Mikkelsen
Can you try this:
sampleGridView.Rows(0).Cells.Count?
You could place this in Prerender to get the count.
Finn Stampe Mikkelsen replied to Rajeev Gopal
I know the count of cells and it is correct and as expected in regard to the
SqlDataSource.Select command... What i need is a way to dynamicly determin
if i wan't to show a specific column of the data bound from the
SqlDataSource.
If for some reason i dont want to see the 3rd column, i want to do a
.visible = false; to the property of that column. I cannot do that, but i
can do it the individuel rows 3rd cell (Cells[3]). This leaves the header
row visible and indicates to the user that data is invisible.
Whar i do not understand is, why the databound gridview, after the dataBind,
cannot return a correct column.count but the individual rows of the same
gridview can... I do not see the reason for this and think there must be some
hack to do it...
/Finn
Databinding editable GridView with SqlDataSource on button click .NET Framework This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the SqlDataSource to allow the GridView to be editable. I have now been able to get the GridView to display data
Insert Row in GridView using SqlDataSource and update to database ? .NET Framework I added new rows to the GridView with the following code. I am using SqlDataSource and Sql Server 2000 Northwind Database Customers table. Dim sqlarg As New DataSourceSelectArguments Dim dv Dim drNewRow As Data.DataRowView = dv.AddNew drNewRow(0) = "LUQ1" drNewRow(1) = "LUQMAN" drNewRow.EndEdit() GridView.DataSource = dv GridView.DataBind() The above code is just adding the row on the fly, but after adding various Best Regards, Luqman ASP.NET Discussions DataSourceSelectArguments (1) System.Data.DataView (1) SqlDataSource1.Select (1) GridView.DataSource (1) GridView.DataBind (1) Data.DataRowView (1) SqlDataSource (1) DataRowView (1) You can add
ASP.NET SQLDataSource.SelectCommand .NET Framework Guys using the below code how do I obtain the results from the select query? / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = / / Create new SQLDataSource / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = SqlDataSource SQLDataSourceUsersDB = new SqlDataSource(); SQLDataSourceUsersDB.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = / / Define SQLDataSource Command Types / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = SQLDataSourceUsersDB.SelectCommandType = SqlDataSourceCommandType.Text; / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = / / Create Insert and Select Commands / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = SQLDataSourceUsersDB.SelectCommand = "SELECT * FROM SQLDataSourceUsersDB.SelectParameters.Add("Email", txtEmail.Text.ToString()); C# Discussions SQLDataSourceUsersDB.SelectCommandType (1) SQLDataSourceUsersDB.SelectCommand (1) SQLDataSource.SelectCommand (1) SqlDataSourceCommandType (1) SQLDataSourceUsersDB (1) WebConfigurationManager.ConnectionStrings (1) ConfigurationManager.ConnectionStrings (1) WebConfigurationManager (1) we in any case, you'll have to bind SQLDataSourceUsersDB to an appropriate control, like a GridView . . . or perhaps one of your own devise the "conventional" way of using a SqlDataSource in ASP.NET is something along the lines of: id = "SqlDataSource1" runat = "server" DataSourceMode = "DataReader
Im Codebehind erzeugte SqlDataSource u. Gridview führen zur Exception beim Paging .NET Framework Hallo Newsgroup, ich möchte gerne eine SqlDataSource und ein Gridview im Codebehind erzeugen. Das Codebehind soll dabei auch Paging unterstützen. Soweit wird auch auf der Versuche ich jetzt aber die zweite Seite des Gridviews anzuzeigen, erhalte ich folgende Fehlermeldung: "Die GridView gvTest löste das Ereignis PageIndexChanging aus, das nicht behandelt wurde." Beim Debuggen komme ich gar Gruß Stefan Hier ist mein Code: Private WithEvents m_gv As New System.Web.UI.WebControls.GridView Private WithEvents m_ds As New System.Web.UI.WebControls.SqlDataSource Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Portal.Global.GetConnectionString() m_ds.SelectCommand = "SELECT Pos_NR, taetigkeit, dauer FROM Taetigkeiten" m_ds.DataSourceMode = SqlDataSourceMode.DataSet 'Gridview hinzufügen m_gv.ID = "gvTest" DCPUniDetailGrids.Controls.Add(m_gv) m_gv.PageSize = 3 m_gv.AllowPaging = True m_gv