Hi, I have a bound datagrid in c# using the code below. My problem is that I need to add an extra column as the last column presented which creates a hyperlinkfield using the value of ExpedioRef attached to a URL.
I have tried t do this in the design view of the datagrid using the wizard to add the new column 'History' and field 'view' with value of expedioref but it places the column at the beginning every time. Please could you tell me how to get this column to appear on the left of the other columns, not before.
Alternatively if would be better to use the already ato generated ExpedioRef field i'm returning and add a hyperlink to it, but don't know how to do this.
I can't use the normal datagrid because I am passing in a variable as parameter in the SQL string.
Thanks
Debs
OracleConnectio n con = new OracleConnectio n();
con.ConnectionS tring = ConfigurationMa nager.Connectio nStrings["NewExpedioDevS tring"].ConnectionStri ng;
string cmdQuery = "SELECT R_EXPEDIOREFERE NCE ExpedioRef,R_CU STOMERREFERENCE CustomerRef,R_R EQUESTSTATUS Status, R_REQUESTTASK Task FROM aradmin.exp__re quest WHERE (r_source = 'KANA' AND BFG_CONTRACTID= '" + Session["BFGCONTRAC TID"].ToString() + "')";
OracleCommand cmd = new OracleCommand(c mdQuery);
try
{
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Tex t;
OracleDataReade r reader = cmd.ExecuteRead er();
dtgOpenOrders.D ataSource = reader;
dtgOpenOrders.D ataBind();
20 1792 Plater 7,872
Recognized Expert Expert
In your SQL statement, have the SELECT return an extra column. That extra column will be your scratch space column and you can then play with/overwrite the data in it.
PS: Unless you're using .NET older then 2.0, you should be using the DataGridView object.
In your SQL statement, have the SELECT return an extra column. That extra column will be your scratch space column and you can then play with/overwrite the data in it.
PS: Unless you're using .NET older then 2.0, you should be using the DataGridView object.
Hi thanks for such a quick response, yes sorry I am using the gridview object. Could you give me an example of how to do the above (sorry to be a pain - new to all this)
thanks
Debs
Plater 7,872
Recognized Expert Expert
You have an SQL statement that selects say X number of columns (in your case it appears to be 4), just request one of the columns a 2nd time.
I named it SpareColumn below, but you could name it something more suitable to your needs. -
OracleConnection con = new OracleConnection();
-
con.ConnectionString = ConfigurationManager.ConnectionStrings["NewExpedioDevString"].ConnectionString;
-
string cmdQuery = "SELECT
-
R_EXPEDIOREFERENCE ExpedioRef,
-
R_CUSTOMERREFERENCE CustomerRef,
-
R_REQUESTSTATUS Status,
-
R_REQUESTTASK Task,
-
R_EXPEDIOREFERENCE SpareColumn,
-
FROM aradmin.exp__request WHERE (r_source = 'KANA' AND BFG_CONTRACTID='" + Session["BFGCONTRACTID"].ToString() + "')";
-
-
OracleCommand cmd = new OracleCommand(cmdQuery);
-
try
-
{
-
con.Open();
-
cmd.Connection = con;
-
cmd.CommandType = CommandType.Text;
-
Now you will have an extra column to use as scratch space.
I recomend you transfer into a DataSet (or DataTable) instead of using a datareader.
That way you can manipulate your DataSet before setting it as the datasource for your gridview object.
Alternatively, you can edit the gridview object after the datasource has been applied. You will have that extra column in there to toy with. (I use this in my own project to a pretty good success)
You have an SQL statement that selects say X number of columns (in your case it appears to be 4), just request one of the columns a 2nd time.
I named it SpareColumn below, but you could name it something more suitable to your needs. -
OracleConnection con = new OracleConnection();
-
con.ConnectionString = ConfigurationManager.ConnectionStrings["NewExpedioDevString"].ConnectionString;
-
string cmdQuery = "SELECT
-
R_EXPEDIOREFERENCE ExpedioRef,
-
R_CUSTOMERREFERENCE CustomerRef,
-
R_REQUESTSTATUS Status,
-
R_REQUESTTASK Task,
-
R_EXPEDIOREFERENCE SpareColumn,
-
FROM aradmin.exp__request WHERE (r_source = 'KANA' AND BFG_CONTRACTID='" + Session["BFGCONTRACTID"].ToString() + "')";
-
-
OracleCommand cmd = new OracleCommand(cmdQuery);
-
try
-
{
-
con.Open();
-
cmd.Connection = con;
-
cmd.CommandType = CommandType.Text;
-
Now you will have an extra column to use as scratch space.
I recomend you transfer into a DataSet (or DataTable) instead of using a datareader.
That way you can manipulate your DataSet before setting it as the datasource for your gridview object.
Alternatively, you can edit the gridview object after the datasource has been applied. You will have that extra column in there to toy with. (I use this in my own project to a pretty good success)
OK sounds like the second option for me,
the following is my gridview object & binding, could you give me an example of how to edit this object to add a hyerlink to the new SpareColumn fields please, sorry to ask for more but really am stuck on this one. Got some training booked for next week so will leave you alone then ;O)
dtgOpenOrders.D ataSource = reader;
dtgOpenOrders.D ataBind();
Plater 7,872
Recognized Expert Expert
Well I am sure there is a cleaner way to do this, try something like this: - protected void procAddingHyperLink()
-
{
-
string msg = "";
-
string href = "ManagerSiteInfo.aspx?siteid=";
-
int retdateidx = -1;
-
if (dtgOpenOrders.HeaderRow != null)
-
{
-
for (int i = 0; i < gvOverdueSites.HeaderRow.Cells.Count; i++)
-
{
-
if (dtgOpenOrders.HeaderRow.Cells[i].Text == "Spare Column")
-
{//find the column index with that name
-
retdateidx = i;
-
}
-
}
-
if (retdateidx!=-1)
-
{
-
for (int i = 0; i < gvOverdueSites.Rows.Count; i++)
-
{
-
//this would pull the text from the first column
-
msg = dtgOpenOrders.Rows[i].Cells[0].Text;
-
//create a hyperlink object
-
HyperLink hl = new HyperLink();
-
hl.Text = msg;
-
hl.NavigateUrl = href + msg.Replace("&", "&");
-
dtgOpenOrders.Rows[i].Cells[retdateidx].Controls.Add(hl);
-
}//end of forloop
-
}
-
}
-
}
-
Well I am sure there is a cleaner way to do this, try something like this: - protected void procAddingHyperLink()
-
{
-
string msg = "";
-
string href = "ManagerSiteInfo.aspx?siteid=";
-
int retdateidx = -1;
-
if (dtgOpenOrders.HeaderRow != null)
-
{
-
for (int i = 0; i < gvOverdueSites.HeaderRow.Cells.Count; i++)
-
{
-
if (dtgOpenOrders.HeaderRow.Cells[i].Text == "Spare Column")
-
{//find the column index with that name
-
retdateidx = i;
-
}
-
}
-
if (retdateidx!=-1)
-
{
-
for (int i = 0; i < gvOverdueSites.Rows.Count; i++)
-
{
-
//this would pull the text from the first column
-
msg = dtgOpenOrders.Rows[i].Cells[0].Text;
-
//create a hyperlink object
-
HyperLink hl = new HyperLink();
-
hl.Text = msg;
-
hl.NavigateUrl = href + msg.Replace("&", "&");
-
dtgOpenOrders.Rows[i].Cells[retdateidx].Controls.Add(hl);
-
}//end of forloop
-
}
-
}
-
}
-
You are an absolute superstar thank you so much, works a treat - think I might have to marry you.
;O)
Next question - how do i add pageing & Sorting to this? (it's nto available int he design view wizard mode of gridview.
Thanks
Debs
Plater 7,872
Recognized Expert Expert
There is a property in the properies window where you turn this on.
You will need to assign an event for it (it will help you with it)
There is a property in the properies window where you turn this on.
You will need to assign an event for it (it will help you with it)
I get a system error when i use properties to add paging:
dataSystem.NotS upportedExcepti on: The data source does not support server-side data paging. at System.Web.UI.D ataSourceView.R aiseUnsupported CapabilityError (DataSourceCapa bilities capability) at System.Web.UI.D ataSourceSelect Arguments.Raise UnsupportedCapa bilitiesError(D ataSourceView view) at System.Web.UI.W ebControls.Read OnlyDataSourceV iew.ExecuteSele ct(DataSourceSe lectArguments arguments) at System.Web.UI.D ataSourceView.S elect(DataSourc eSelectArgument s arguments, DataSourceViewS electCallback callback) at System.Web.UI.W ebControls.Grid View.CreateChil dControls(IEnum erable dataSource, Boolean dataBinding) at System.Web.UI.W ebControls.Comp ositeDataBoundC ontrol.PerformD ataBinding(IEnu merable data) at
Any ideas ?
Thanks
Debs
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Billy Jacobs |
last post by:
I am using a datagrid to display some data. I need to
create 2 header rows for this grid with columns of
varying spans. In html it would be the following.
<Table>
<tr>
<td colspan=8>Official Impact Summary</td>
</tr>
<tr>
<td colspan=2></td>
|
by: Paul |
last post by:
Hey there,
I have a DataGrid bound to a DataTable. When a user
selects a row, I want to send the UNQ_ID (which is in a
column with a width of zero, or it's visible parameter set
to false) for that row to a function. I got the row by :
DataGrid.Items(DataGrid.SelectedIndex) Then I need to
use .Cells(<index here>) and get the index of the UNQ_ID
column. I can't use the DataTable I bound it to, because
the user can sort and sometimes...
|
by: Frederik |
last post by:
Hi all,
I'm building a C# application that uses a M$ Acces database. In one of
the queries I use something like the following:
SELECT id FROM mytable WHERE id IN (20, 12, 21, 14)
The result is fine, except that the order of the id's is not
preserved. It seems to be ordered ascending. How can I keep the order
I used as input?
|
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 displays with the template columns
showing the Title and the Author from the first row in all rows. The other
none template columns are fine. Obviously I am not understanding something
here. What am I missing?????
--
Barry Fitzgerald
|
by: Amber |
last post by:
The DataGrid allows you to make columns visible or invisible on demand
- even edit and other special columns. This article will show you how
it is done.
Some developers have reported problems controlling the visibility of
columns in the DataGrid control. The problem usually comes down to one
fact. The DataGrid has a property called AutoGenerateColumns. The
default value is "True". This means that when AutoGenerateColumns is
set to True,...
| |
by: Allen K |
last post by:
Hi,
I'm programmatically creating a HyperLink column for my datagrd ( in
addition to Bound Columns created through the VS.NET Visual Interface ).
However, when a Postback occurs, this column simply disappears, as if it
doesn't exist in ViewState.. However, the columns I created in the VS.NET
DataGrid editor appear just fine.. Can someone help me??
Heres my code:
|
by: tshad |
last post by:
I have a datagrid that I want to add a new column to. This column will only
be visible under certain conditions. So I want to set the column
visible=false. Then when the right condition happens to change it to
visible=true.
You can't do that with a bound column (no ID), but you can create a
templatecolumn with a label.
To make these visible, I am going through each datagriditem and making them
visible after I have bound the data to...
|
by: Opa |
last post by:
Hi,
I have a DataGrid, whose sourceI am exporting to Excel. This works fine
except for the Column ordering. My datasource is not a datatable, with a
typical
SELECT statement where I can select the column orders. Instead the datasource
is a class which implements IList, containing a collection of my data. My
problem
again is that I don't know how to control the order of the columns that are
exported.
|
by: Brett Wesoloski |
last post by:
I am new to using template columns. I am just trying to create a data grid
with a bound column and another column with a imagebutton in it.
What I have always done in the past was to then create a datatable and bind
that to the datagrid.
Where is my code to bind the grid to the datatable.
DataTable dt = new DataTable();
dt.Columns.Add("FundDescription");
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |