Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Datareader, Datagrid and hyperlinks

Reply
Thread Tools

Datareader, Datagrid and hyperlinks

 
 
Grant
Guest
Posts: n/a
 
      12-17-2004
I am filling a datareader and then assigning the reader to the datagrid as
follows:

SqlDataReader reader = ADOConnect.populateDatareader();
AllResultsDataGrid.DataSource = reader;
AllResultsDataGrid.HeaderStyle.Font.Bold = true;
AllResultsDataGrid.DataBind();

My question is how do I specify that foreach row in the first column - the
text is a hyperlink? This column contains an ID which Id like to have as a
hyperlink so that the user can be directed to another page where they can
edit information for that record. I can do this when binding the datagrid to
a recordset, but Id like to use the datareader instead if possible.

Another question I have with this datagrid is, I want to be able to delete a
row from this page, so could I add an additional column at runtime with a
button or link foreach record - with a funtion attached?

Cheers,
Grant


 
Reply With Quote
 
 
 
 
Andrew L. Van Slaars
Guest
Posts: n/a
 
      12-17-2004
If you have created the datagrid through tags in the designer (assuming VS
is your editor), you can right click on it, choose the "property builder"
option and add a hyperLinkColumn to the grid and move it to the first
position in the list of columns to make it the first column.
Hope this helps
-Andrew

"Grant" <> wrote in message
news:%...
>I am filling a datareader and then assigning the reader to the datagrid as
>follows:
>
> SqlDataReader reader = ADOConnect.populateDatareader();
> AllResultsDataGrid.DataSource = reader;
> AllResultsDataGrid.HeaderStyle.Font.Bold = true;
> AllResultsDataGrid.DataBind();
>
> My question is how do I specify that foreach row in the first column - the
> text is a hyperlink? This column contains an ID which Id like to have as a
> hyperlink so that the user can be directed to another page where they can
> edit information for that record. I can do this when binding the datagrid
> to a recordset, but Id like to use the datareader instead if possible.
>
> Another question I have with this datagrid is, I want to be able to delete
> a row from this page, so could I add an additional column at runtime with
> a button or link foreach record - with a funtion attached?
>
> Cheers,
> Grant
>



 
Reply With Quote
 
 
 
 
Andrew L. Van Slaars
Guest
Posts: n/a
 
      12-17-2004
I just saw your second question... you could do this using the same steps as
listed in my last response, but instead of the hyperlink column, use the
button column, or you could use a template column if you wanted more control
and options within the cells.

-Andrew

"Grant" <> wrote in message
news:%...
>I am filling a datareader and then assigning the reader to the datagrid as
>follows:
>
> SqlDataReader reader = ADOConnect.populateDatareader();
> AllResultsDataGrid.DataSource = reader;
> AllResultsDataGrid.HeaderStyle.Font.Bold = true;
> AllResultsDataGrid.DataBind();
>
> My question is how do I specify that foreach row in the first column - the
> text is a hyperlink? This column contains an ID which Id like to have as a
> hyperlink so that the user can be directed to another page where they can
> edit information for that record. I can do this when binding the datagrid
> to a recordset, but Id like to use the datareader instead if possible.
>
> Another question I have with this datagrid is, I want to be able to delete
> a row from this page, so could I add an additional column at runtime with
> a button or link foreach record - with a funtion attached?
>
> Cheers,
> Grant
>



 
Reply With Quote
 
Grant
Guest
Posts: n/a
 
      12-17-2004
Thanks for replying Andrew that did the trick. One more question though, I
have set one of the columns to be a delete colum as in the following code:

ButtonColumn hlcDelete = new ButtonColumn();
hlcDelete.Text = "Delete";

Problem is when the button is created it has no ID or event handler assigned
to it. i need to be able to determine either what row was selected or what
the value of the ID field in that row is so that I can create a SQL query to
delete that record. There are not any samples that i can find - all of them
are done in ASP code, and I prefer not to use the designer to set these
sorts of things. Can this sort of thing be done in c# code when Im binding
the datareader?

Cheers,
Grant


"Andrew L. Van Slaars" <> wrote in message
news:...
>I just saw your second question... you could do this using the same steps
>as listed in my last response, but instead of the hyperlink column, use the
>button column, or you could use a template column if you wanted more
>control and options within the cells.
>
> -Andrew
>
> "Grant" <> wrote in message
> news:%...
>>I am filling a datareader and then assigning the reader to the datagrid as
>>follows:
>>
>> SqlDataReader reader = ADOConnect.populateDatareader();
>> AllResultsDataGrid.DataSource = reader;
>> AllResultsDataGrid.HeaderStyle.Font.Bold = true;
>> AllResultsDataGrid.DataBind();
>>
>> My question is how do I specify that foreach row in the first column -
>> the text is a hyperlink? This column contains an ID which Id like to have
>> as a hyperlink so that the user can be directed to another page where
>> they can edit information for that record. I can do this when binding the
>> datagrid to a recordset, but Id like to use the datareader instead if
>> possible.
>>
>> Another question I have with this datagrid is, I want to be able to
>> delete a row from this page, so could I add an additional column at
>> runtime with a button or link foreach record - with a funtion attached?
>>
>> Cheers,
>> Grant
>>

>
>



 
Reply With Quote
 
Grant
Guest
Posts: n/a
 
      12-18-2004
No worries I figured it out. I just set the text using the property builder
then assigned an event handler to it. Then get the cell value using

TableCell itemCell = e.Item.Cells[2];
string item = itemCell.Text;

Couldnt be easier.

Cheers,
Grant

"Grant" <> wrote in message
news:O%23bWd%...
> Thanks for replying Andrew that did the trick. One more question though, I
> have set one of the columns to be a delete colum as in the following code:
>
> ButtonColumn hlcDelete = new ButtonColumn();
> hlcDelete.Text = "Delete";
>
> Problem is when the button is created it has no ID or event handler
> assigned to it. i need to be able to determine either what row was
> selected or what the value of the ID field in that row is so that I can
> create a SQL query to delete that record. There are not any samples that i
> can find - all of them are done in ASP code, and I prefer not to use the
> designer to set these sorts of things. Can this sort of thing be done in
> c# code when Im binding the datareader?
>
> Cheers,
> Grant
>
>
> "Andrew L. Van Slaars" <> wrote in message
> news:...
>>I just saw your second question... you could do this using the same steps
>>as listed in my last response, but instead of the hyperlink column, use
>>the button column, or you could use a template column if you wanted more
>>control and options within the cells.
>>
>> -Andrew
>>
>> "Grant" <> wrote in message
>> news:%...
>>>I am filling a datareader and then assigning the reader to the datagrid
>>>as follows:
>>>
>>> SqlDataReader reader = ADOConnect.populateDatareader();
>>> AllResultsDataGrid.DataSource = reader;
>>> AllResultsDataGrid.HeaderStyle.Font.Bold = true;
>>> AllResultsDataGrid.DataBind();
>>>
>>> My question is how do I specify that foreach row in the first column -
>>> the text is a hyperlink? This column contains an ID which Id like to
>>> have as a hyperlink so that the user can be directed to another page
>>> where they can edit information for that record. I can do this when
>>> binding the datagrid to a recordset, but Id like to use the datareader
>>> instead if possible.
>>>
>>> Another question I have with this datagrid is, I want to be able to
>>> delete a row from this page, so could I add an additional column at
>>> runtime with a button or link foreach record - with a funtion attached?
>>>
>>> Cheers,
>>> Grant
>>>

>>
>>

>
>



 
Reply With Quote
 
Ben Strackany
Guest
Posts: n/a
 
      12-22-2004
You could also check out the ASP.NET quick start pages at

http://samples.gotdotnet.com/quickstart/aspplus/

The "Server-side data access" pages go through the datagrid at a high level.

--
Ben Strackany
www.developmentnow.com


"Grant" <> wrote in message
news:...
> No worries I figured it out. I just set the text using the property

builder
> then assigned an event handler to it. Then get the cell value using
>
> TableCell itemCell = e.Item.Cells[2];
> string item = itemCell.Text;
>
> Couldnt be easier.
>
> Cheers,
> Grant
>
> "Grant" <> wrote in message
> news:O%23bWd%...
> > Thanks for replying Andrew that did the trick. One more question though,

I
> > have set one of the columns to be a delete colum as in the following

code:
> >
> > ButtonColumn hlcDelete = new ButtonColumn();
> > hlcDelete.Text = "Delete";
> >
> > Problem is when the button is created it has no ID or event handler
> > assigned to it. i need to be able to determine either what row was
> > selected or what the value of the ID field in that row is so that I can
> > create a SQL query to delete that record. There are not any samples that

i
> > can find - all of them are done in ASP code, and I prefer not to use the
> > designer to set these sorts of things. Can this sort of thing be done in
> > c# code when Im binding the datareader?
> >
> > Cheers,
> > Grant
> >
> >
> > "Andrew L. Van Slaars" <> wrote in message
> > news:...
> >>I just saw your second question... you could do this using the same

steps
> >>as listed in my last response, but instead of the hyperlink column, use
> >>the button column, or you could use a template column if you wanted more
> >>control and options within the cells.
> >>
> >> -Andrew
> >>
> >> "Grant" <> wrote in message
> >> news:%...
> >>>I am filling a datareader and then assigning the reader to the datagrid
> >>>as follows:
> >>>
> >>> SqlDataReader reader = ADOConnect.populateDatareader();
> >>> AllResultsDataGrid.DataSource = reader;
> >>> AllResultsDataGrid.HeaderStyle.Font.Bold = true;
> >>> AllResultsDataGrid.DataBind();
> >>>
> >>> My question is how do I specify that foreach row in the first column -
> >>> the text is a hyperlink? This column contains an ID which Id like to
> >>> have as a hyperlink so that the user can be directed to another page
> >>> where they can edit information for that record. I can do this when
> >>> binding the datagrid to a recordset, but Id like to use the datareader
> >>> instead if possible.
> >>>
> >>> Another question I have with this datagrid is, I want to be able to
> >>> delete a row from this page, so could I add an additional column at
> >>> runtime with a button or link foreach record - with a funtion

attached?
> >>>
> >>> Cheers,
> >>> Grant
> >>>
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically add hyperlinks and buttons to a datagrid Richard Jonker ASP .Net Datagrid Control 2 10-03-2006 05:48 AM
Datareader, Datagrid and hyperlinks Grant ASP .Net Building Controls 5 12-22-2004 04:18 PM
DataSet bound DataGrid with hyperlinks question Alex ASP .Net 2 04-15-2004 09:21 PM
Datagrid and Hyperlinks,,, Steve Randall ASP .Net Web Controls 1 01-07-2004 11:11 AM
Re: DataGrid Header Sort Hyperlinks Jay ASP .Net 0 08-30-2003 12:53 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57