Hello,
First, thanks to felix for his answer.
But :-( , I'm feeling newbie :! I' don't understand all the situation.
The trouble :
Always in the road whith my Datagrid and my ItemTemplate with a Control
HyperLink.
I would like to fix many properties of this Control Hyperlink in the Code
Behind. I'm using the Datagrid OnItemCreated Event.
So, I can establish a lot of properties of the Control like that :
--- In the file .aspx, in the Datagrid Control :
OnItemCreated="myDatagrid_ItemCreated"
---- In the code behind file (.aspx .vb)
Sub myDatagrid_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lnkControl"),
HyperLink).Text="myText"
End If
-->> It's OK.
But I have always the problem with the property NavigateUrl of thisControl
Hyperlink (or CommandArgument property for an another control like
ImageButton).
Question : How can I access to the value of a cell in the DataGrid in the
OnItemCreated Event. I'm referring to thedata bound in the datagrid.
Example of try :
CType(e.Item.FindControl("lnkFamBreDetail"),
HyperLink).NavigateUrl="mapage.aspx?" & Value (of my column bound)
OR CType(e.Item.FindControl("lnkControl"),
Hyperlink).CommandArgument = DataBound
The DataGrid is bound with a DataView (Based on a dataset).
I ' ve try this Felix's Solution (thanks)) but it does not work or i 'm very
stupid :-(
If e.Item.ItemType = ListItemType.Item Then
Dim drvTemp As System.Data.DataRowView
drvTemp = CType(e.Item.DataItem, System.Data.DataRowView)
CType(e.Item.FindControl("lnkControl"),
Hyperlink).CommandArgument = CType(drvTemp.Row.Item("Column"),
System.String) --> Here I have an error. My Column is not recognized.
End if
how referred to the databound?
I'm lost in the deep datagrid ....
Thanks for you help
fabrice
(sorry for my poor english) 2 1824
Hi Fabrice,
I would suggest you to use ItemDataBound event rather than ItemCreated
event, because in the first event you can access underlying data source.
The following code snippet shows how to get data and reference of columns:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim link As HyperLink =
Ctype(e.Item.FindControl(“lnkFamBreDetail”),Hy perLink)
Link.NavigateUrl="mapage.aspx?queryID=" + drv(“Column_name”).ToString
End If
HTH
Elton Wang
"Fabrice" wrote: Hello,
First, thanks to felix for his answer.
But :-( , I'm feeling newbie :! I' don't understand all the situation. The trouble :
Always in the road whith my Datagrid and my ItemTemplate with a Control HyperLink. I would like to fix many properties of this Control Hyperlink in the Code Behind. I'm using the Datagrid OnItemCreated Event.
So, I can establish a lot of properties of the Control like that :
--- In the file .aspx, in the Datagrid Control :
OnItemCreated="myDatagrid_ItemCreated"
---- In the code behind file (.aspx .vb)
Sub myDatagrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lnkControl"), HyperLink).Text="myText"
End If
-->> It's OK.
But I have always the problem with the property NavigateUrl of thisControl Hyperlink (or CommandArgument property for an another control like ImageButton).
Question : How can I access to the value of a cell in the DataGrid in the OnItemCreated Event. I'm referring to thedata bound in the datagrid.
Example of try : CType(e.Item.FindControl("lnkFamBreDetail"), HyperLink).NavigateUrl="mapage.aspx?" & Value (of my column bound) OR CType(e.Item.FindControl("lnkControl"), Hyperlink).CommandArgument = DataBound
The DataGrid is bound with a DataView (Based on a dataset).
I ' ve try this Felix's Solution (thanks)) but it does not work or i 'm very stupid :-(
If e.Item.ItemType = ListItemType.Item Then
Dim drvTemp As System.Data.DataRowView drvTemp = CType(e.Item.DataItem, System.Data.DataRowView) CType(e.Item.FindControl("lnkControl"), Hyperlink).CommandArgument = CType(drvTemp.Row.Item("Column"), System.String) --> Here I have an error. My Column is not recognized.
End if
how referred to the databound?
I'm lost in the deep datagrid .... Thanks for you help
fabrice (sorry for my poor english)
Hi.
It works fine with OnItemDataBound. Thanks a lot.
Have a nice week end.
fabrice.
"Elton W" <El****@discussions.microsoft.com> a crit dans le message de
news: 32**********************************@microsoft.com... Hi Fabrice,
I would suggest you to use ItemDataBound event rather than ItemCreated event, because in the first event you can access underlying data source.
The following code snippet shows how to get data and reference of columns:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView) Dim link As HyperLink = Ctype(e.Item.FindControl("lnkFamBreDetail"),HyperL ink) Link.NavigateUrl="mapage.aspx?queryID=" + drv("Column_name").ToString End If
HTH
Elton Wang
"Fabrice" wrote:
Hello,
First, thanks to felix for his answer.
But :-( , I'm feeling newbie :! I' don't understand all the situation. The trouble :
Always in the road whith my Datagrid and my ItemTemplate with a Control HyperLink. I would like to fix many properties of this Control Hyperlink in the Code Behind. I'm using the Datagrid OnItemCreated Event.
So, I can establish a lot of properties of the Control like that :
--- In the file .aspx, in the Datagrid Control :
OnItemCreated="myDatagrid_ItemCreated"
---- In the code behind file (.aspx .vb)
Sub myDatagrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lnkControl"), HyperLink).Text="myText"
End If
-->> It's OK.
But I have always the problem with the property NavigateUrl of thisControl Hyperlink (or CommandArgument property for an another control like ImageButton).
Question : How can I access to the value of a cell in the DataGrid in the OnItemCreated Event. I'm referring to thedata bound in the datagrid.
Example of try : CType(e.Item.FindControl("lnkFamBreDetail"), HyperLink).NavigateUrl="mapage.aspx?" & Value (of my column bound) OR CType(e.Item.FindControl("lnkControl"), Hyperlink).CommandArgument = DataBound
The DataGrid is bound with a DataView (Based on a dataset).
I ' ve try this Felix's Solution (thanks)) but it does not work or i 'm very stupid :-(
If e.Item.ItemType = ListItemType.Item Then
Dim drvTemp As System.Data.DataRowView drvTemp = CType(e.Item.DataItem, System.Data.DataRowView) CType(e.Item.FindControl("lnkControl"), Hyperlink).CommandArgument = CType(drvTemp.Row.Item("Column"), System.String) --> Here I have an error. My Column is not recognized.
End if
how referred to the databound?
I'm lost in the deep datagrid .... Thanks for you help
fabrice (sorry for my poor english) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Felix |
last post by:
Is it possible to clone a datagrid?
I've created a datagrid on my aspx page, editing various attributes,
adding columns, etc. I would like to, in code, create an arbitrary
number of these...
|
by: Jon Slaughter |
last post by:
I'm having a little trouble understanding what the slicing problem is.
In B.S.'s C++ PL3rdEd he says
"Becayse the Employee copy functions do not know anything about Managers,
only the Employee...
|
by: Peter |
last post by:
I have a DataGrid control on a form and I used the Auto Format feature to format the grid.
The problem is now if I resize a column in my code I loose some of the formats - some of the grid colors...
|
by: Morten |
last post by:
Hi!
I have a problem displaying some values in a datagrid. I have an array that
consists of a number of objects. Each object has 2 properties: Name and a
list of web addresses. (e.g: Name:...
|
by: |
last post by:
I have a datagrid with a template column that has a hyperlink and a label.
The hyperlink text is bound to Title from my dataset and the label text is
bound to Author in the dataset. The grid...
|
by: vinayak |
last post by:
Hi
I am displaying data in Datagrid in ASP.NET with
Edit/Update functionality for each row. On the same page I
have 2 Button controls which submits the request to
server. These button controls...
|
by: Girish |
last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a
huge learning experience..
My problem. I have a requirement to display a gird with a gird. Within the
embedded grid,...
|
by: Ron L |
last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying
to display in a datagrid. This datasource has 4 columns that I am
interested in here, a text column and 3 value columns...
|
by: Brock |
last post by:
Thanks in advance... (you can see a screenshot of what my form looks
like currently at http://www.juggernautical.com/DataGrid.jpg - the
Datalist is super-imposed in 'design view' but the DataGrid...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |