473,799 Members | 3,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LinkButton in a datagrid???

Can someone tell me how I do a response.redire ct using a linkbutton in a
datagrid!

I want to use the record id in a database to send a querystring to an HTML
editor so that users are able to edit a particular page they have chosen from
a datagrid!

EG: If a user clicks the linkbutton in a datagrid it takes you to a page
with the following url...

.../editor.aspx?id= 23

Would appritiate any help!

Thanks
Nov 19 '05 #1
4 4095
Hi Tim,

Here's the idea. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

Private Sub DataGrid1_ItemC ommand _
(ByVal source As Object, _
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) _
Handles DataGrid1.ItemC ommand
' Check for the right link button
If e.CommandName = "Select" Then
' Build the redirection URL
Response.Redire ct("othersite.a spx?id=" & e.CommandArgume nt)
End If
End Sub

Function CreateDataSourc e() As DataTable
'ProductId
'DownloadURL()
'title()
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("ProductId" , GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("DownloadUR L", GetType(String) ))
dt.Columns.Add( New DataColumn _
("title", GetType(String) ))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "URL " + i.ToString()
dr(2) = "Item " + i.ToString()
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:BoundColum n DataField="Prod uctId"
Visible="False" ></asp:BoundColumn >
<asp:BoundColum n DataField="Down loadURL"
Visible="False" ></asp:BoundColumn >
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on ID="lnkArticle "
CommandArgument ='<%#DataBinder .Eval(Container , "DataItem.Produ ctId")%>'
Runat="server" Text='<%#DataBi nder.Eval(Conta iner, "DataItem.Title ")%>'
CommandName="Se lect" />
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
</form>
"Tim::.." <myatix_at_hotm ail.com> wrote in message
news:BD******** *************** ***********@mic rosoft.com...
Can someone tell me how I do a response.redire ct using a linkbutton in a
datagrid!

I want to use the record id in a database to send a querystring to an HTML
editor so that users are able to edit a particular page they have chosen
from
a datagrid!

EG: If a user clicks the linkbutton in a datagrid it takes you to a page
with the following url...

../editor.aspx?id= 23

Would appritiate any help!

Thanks


Nov 19 '05 #2
Hi Ken,

Thanks for the reply! I have managed to get the copy you sent me to work but
for some reason I just can't get to get it to work with my code!

I am using a datagrid rather than a datatable! Would this effect it in a big
way!

I would be really interested why this doesn't work!

Thanks
This is my code..

<asp:datagrid id="DGPages" runat="server" EnableViewState ="False"
AlternatingItem Style-BackColor="Whit eSmoke" CssClass="txtAr ea"
ShowFooter="fal se" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign ="Center" CellPadding="4" Width="50%"
AutoGenerateCol umns="False"
BorderStyle="Ri dge" BorderWidth="1p x" GridLines="Hori zontal"
BorderColor="Li ghtGray">
<EditItemStyl e BackColor="#EEE EEE"></EditItemStyle>
<AlternatingIte mStyle BackColor="Whit eSmoke"></AlternatingItem Style>
<HeaderStyle Font-Bold="True" HorizontalAlign ="Center"
ForeColor="Whit e" BackColor="Blac k"></HeaderStyle>
<Columns>
<asp:BoundColum n DataField="Page Id"
Visible="False" ></asp:BoundColumn >

<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<img src="../images/page.gif">
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Pag e">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("header") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Des cription">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("descriptio n") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<asp:LinkButt on ID="PageEdit"
CommandArgument ='<%#DataBinder .Eval(Container , "DataItem.PageI d")%>'
Text='<img border=0 src=../images/edit.gif alt=Edit Page>'
CommandName="Se lect" Runat="server">
</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<asp:LinkButt on ID="PagePropert ies"
CommandArgument ='<%#DataBinder .Eval(Container , "DataItem.PageI d")%>'
Runat="server" Text="<img border=0 src=../images/properties.gif alt=Page
Properties>" CommandName="Pr operties">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:datagrid>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

If Not Page.IsPostBack Then

BindData()

End If

End Sub

Sub BindData()

Dim Myconn As New SqlConnection(C onfigurationSet tings.AppSettin gs("strConn"))

Dim cmd As New SqlCommand("Pag eDetails", Myconn)

cmd.CommandType = CommandType.Sto redProcedure

Myconn.Open()

Dim objOfficeName, objID As SqlParameter

objOfficeName = cmd.Parameters. Add("@OfficeNam e", SqlDbType.Char)

'objID = cmd.Parameters. Add("@ID", SqlDbType.Int)

objOfficeName.D irection = ParameterDirect ion.Input

'objID.Directio n = ParameterDirect ion.Input

objOfficeName.V alue = FindOffice()

'objID.Value = 2

Dim myReader As SqlDataReader = cmd.ExecuteRead er()

Dim hasRows As Boolean

hasRows = True

DGPages.DataSou rce = myReader

DGPages.DataBin d()

If DGPages.Items.C ount = 0 Then

lblNoContent.Vi sible = True

lblNoContent.Te xt = "There a currently no pages for" & " " & FindOffice()

End If

myReader.Close( )

Myconn.Close()

End Sub 'Loads Data into Datagrid

Private Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DGPages.ItemCom mand

' Check for the right link button

If e.CommandName = "Select" Then

' Build the redirection URL

Response.Redire ct("../default.aspx?id =" & e.CommandArgume nt)

End If

End Sub
Nov 19 '05 #3
Hey Tim,

Why not do it the simple way and use a hyperlink column?

<asp:hyperlinkc olumn DataNavigateUrl Field="pageid"
DataNavigateUrl FormatString="d estination.aspx ?id={0}"
DataTextField=" PageId"></asp:hyperlinkco lumn>

"Tim::.." <myatix_at_hotm ail.com> wrote in message
news:E9******** *************** ***********@mic rosoft.com...
Hi Ken,

Thanks for the reply! I have managed to get the copy you sent me to work
but
for some reason I just can't get to get it to work with my code!

I am using a datagrid rather than a datatable! Would this effect it in a
big
way!

I would be really interested why this doesn't work!

Thanks
This is my code..

<asp:datagrid id="DGPages" runat="server" EnableViewState ="False"
AlternatingItem Style-BackColor="Whit eSmoke" CssClass="txtAr ea"
ShowFooter="fal se" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign ="Center" CellPadding="4" Width="50%"
AutoGenerateCol umns="False"
BorderStyle="Ri dge" BorderWidth="1p x" GridLines="Hori zontal"
BorderColor="Li ghtGray">
<EditItemStyl e BackColor="#EEE EEE"></EditItemStyle>
<AlternatingIte mStyle
BackColor="Whit eSmoke"></AlternatingItem Style>
<HeaderStyle Font-Bold="True" HorizontalAlign ="Center"
ForeColor="Whit e" BackColor="Blac k"></HeaderStyle>
<Columns>
<asp:BoundColum n DataField="Page Id"
Visible="False" ></asp:BoundColumn >

<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<img src="../images/page.gif">
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Pag e">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("header") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Des cription">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("descriptio n") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<asp:LinkButt on ID="PageEdit"
CommandArgument ='<%#DataBinder .Eval(Container , "DataItem.PageI d")%>'
Text='<img border=0 src=../images/edit.gif alt=Edit Page>'
CommandName="Se lect" Runat="server">
</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<asp:LinkButt on ID="PagePropert ies"
CommandArgument ='<%#DataBinder .Eval(Container , "DataItem.PageI d")%>'
Runat="server" Text="<img border=0 src=../images/properties.gif alt=Page
Properties>" CommandName="Pr operties">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:datagrid>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

If Not Page.IsPostBack Then

BindData()

End If

End Sub

Sub BindData()

Dim Myconn As New
SqlConnection(C onfigurationSet tings.AppSettin gs("strConn"))

Dim cmd As New SqlCommand("Pag eDetails", Myconn)

cmd.CommandType = CommandType.Sto redProcedure

Myconn.Open()

Dim objOfficeName, objID As SqlParameter

objOfficeName = cmd.Parameters. Add("@OfficeNam e", SqlDbType.Char)

'objID = cmd.Parameters. Add("@ID", SqlDbType.Int)

objOfficeName.D irection = ParameterDirect ion.Input

'objID.Directio n = ParameterDirect ion.Input

objOfficeName.V alue = FindOffice()

'objID.Value = 2

Dim myReader As SqlDataReader = cmd.ExecuteRead er()

Dim hasRows As Boolean

hasRows = True

DGPages.DataSou rce = myReader

DGPages.DataBin d()

If DGPages.Items.C ount = 0 Then

lblNoContent.Vi sible = True

lblNoContent.Te xt = "There a currently no pages for" & " " & FindOffice()

End If

myReader.Close( )

Myconn.Close()

End Sub 'Loads Data into Datagrid

Private Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DGPages.ItemCom mand

' Check for the right link button

If e.CommandName = "Select" Then

' Build the redirection URL

Response.Redire ct("../default.aspx?id =" & e.CommandArgume nt)

End If

End Sub


Nov 19 '05 #4
This doesn't provided me with what I require as far as I know!

I also get an error saying "The active scheme does not support the element!

Thanks
"Ken Cox [Microsoft MVP]" wrote:
Hey Tim,

Why not do it the simple way and use a hyperlink column?

<asp:hyperlinkc olumn DataNavigateUrl Field="pageid"
DataNavigateUrl FormatString="d estination.aspx ?id={0}"
DataTextField=" PageId"></asp:hyperlinkco lumn>

"Tim::.." <myatix_at_hotm ail.com> wrote in message
news:E9******** *************** ***********@mic rosoft.com...
Hi Ken,

Thanks for the reply! I have managed to get the copy you sent me to work
but
for some reason I just can't get to get it to work with my code!

I am using a datagrid rather than a datatable! Would this effect it in a
big
way!

I would be really interested why this doesn't work!

Thanks
This is my code..

<asp:datagrid id="DGPages" runat="server" EnableViewState ="False"
AlternatingItem Style-BackColor="Whit eSmoke" CssClass="txtAr ea"
ShowFooter="fal se" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign ="Center" CellPadding="4" Width="50%"
AutoGenerateCol umns="False"
BorderStyle="Ri dge" BorderWidth="1p x" GridLines="Hori zontal"
BorderColor="Li ghtGray">
<EditItemStyl e BackColor="#EEE EEE"></EditItemStyle>
<AlternatingIte mStyle
BackColor="Whit eSmoke"></AlternatingItem Style>
<HeaderStyle Font-Bold="True" HorizontalAlign ="Center"
ForeColor="Whit e" BackColor="Blac k"></HeaderStyle>
<Columns>
<asp:BoundColum n DataField="Page Id"
Visible="False" ></asp:BoundColumn >

<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<img src="../images/page.gif">
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Pag e">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("header") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Des cription">
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<%# Container.DataI tem("descriptio n") %>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<asp:LinkButt on ID="PageEdit"
CommandArgument ='<%#DataBinder .Eval(Container , "DataItem.PageI d")%>'
Text='<img border=0 src=../images/edit.gif alt=Edit Page>'
CommandName="Se lect" Runat="server">
</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<ItemStyle HorizontalAlign ="Center"></ItemStyle>
<ItemTemplate >
<asp:LinkButt on ID="PagePropert ies"
CommandArgument ='<%#DataBinder .Eval(Container , "DataItem.PageI d")%>'
Runat="server" Text="<img border=0 src=../images/properties.gif alt=Page
Properties>" CommandName="Pr operties">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:datagrid>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

If Not Page.IsPostBack Then

BindData()

End If

End Sub

Sub BindData()

Dim Myconn As New
SqlConnection(C onfigurationSet tings.AppSettin gs("strConn"))

Dim cmd As New SqlCommand("Pag eDetails", Myconn)

cmd.CommandType = CommandType.Sto redProcedure

Myconn.Open()

Dim objOfficeName, objID As SqlParameter

objOfficeName = cmd.Parameters. Add("@OfficeNam e", SqlDbType.Char)

'objID = cmd.Parameters. Add("@ID", SqlDbType.Int)

objOfficeName.D irection = ParameterDirect ion.Input

'objID.Directio n = ParameterDirect ion.Input

objOfficeName.V alue = FindOffice()

'objID.Value = 2

Dim myReader As SqlDataReader = cmd.ExecuteRead er()

Dim hasRows As Boolean

hasRows = True

DGPages.DataSou rce = myReader

DGPages.DataBin d()

If DGPages.Items.C ount = 0 Then

lblNoContent.Vi sible = True

lblNoContent.Te xt = "There a currently no pages for" & " " & FindOffice()

End If

myReader.Close( )

Myconn.Close()

End Sub 'Loads Data into Datagrid

Private Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DGPages.ItemCom mand

' Check for the right link button

If e.CommandName = "Select" Then

' Build the redirection URL

Response.Redire ct("../default.aspx?id =" & e.CommandArgume nt)

End If

End Sub


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2181
by: Calvin Lai | last post by:
Hi all, Does anyone know how I could add a confirm (client side) feature on those Delete Linkbutton in DataGrid? Thanks,
0
1312
by: Solomon Shaffer | last post by:
This is very interesting - and odd. I have a number of LinkButtons that are created in a custom data grid that I created. The purpose of the LinkButtons is to provide alphabetical filtering functionality on the grid. Therefore, a LinkButton is added for every letter of the alphabet. I also have a numeric filter button and an "All" button that removes the filter. All of the LinkButtons are wired up to the same event called...
1
1874
by: Bazza Formez | last post by:
Hi, The intended functionality is as follows : I want the user to be able to click on the LinkButton for an individual row in a datagrid, server side sub grabs id for item selected, stores in session & reirects user to new page which retrieves id from session & loads its own grid accordingly. Note that I don't want pass info as a parameter tacked on to the url... and
1
1619
by: Danny Ni | last post by:
Hi, I have a LinkButton inside a datagrid, when this LinkButton is clicked, the program deleete a record in database. I would like to add a confirmation on client side. I know I can do Attributes.Add("onclick",...) to Buttons not in datagrid. But how do I do it for LinkButton in datagrid? TIA
2
2064
by: George Durzi | last post by:
I have to LinkButtons in a DataGrid, and each of them has a Command="Select" attribute set up. When either of hte LinkButton's is clicked, I want the proper row in the DataGrid to be selected, but I then want to do a different operation depending on which LinkButton was clicked. Here's some of the Html out of my DataGrid <asp:TemplateColumn> <ItemTemplate>
6
4257
by: Shivakumar | last post by:
Hi all, Recently i have updated my vs.net 2003 project to vs.net 2005 and i have successfully converted my code and found no problem with all my controls except the one which is the linkbutton. I have added the linkbutton control in my datagrid and it rendered perfectly but whenever i clicked the linkbutton am getting this error 'event' is null or not an object.
7
5274
by: Alex Maghen | last post by:
I have a DataGrid control with a LinkButton command column that deletes the row. What I want to do is set it up so that there's a client-side Confirm alert BEFORE the actual Delete command gets called on the server-side. That's easy to do with normal buttons, etc. as follows... <asp:Button ID="ConfirmBtn" Text="ConfimMe!" OnClientClick="if(!confirm('Are you sure?'))return false;" OnClick="ConfirmBtnClickHandler" Runat="server" /> But...
3
1547
by: settyv | last post by:
Hi, I need to generate PDF stream when i click on Linkbutton in datagrid ..At present i hardcoded the DMS Id and now it is working.But i need to pass DMS ID when click linkbutton.How can i do that? Here is the ASPX code: <asp:datagrid id="grdTentativeResults" Width="800" Runat="server"
5
7379
daJunkCollector
by: daJunkCollector | last post by:
What I am doing here should be obvious. I have a datagrid that displays data properly. I want to create a linkbutton within each row of the datagrid that toggles a label control in the same row visible/invisible. Please refer to the following GUI and Codebehind: <body> <form id="form1" runat="server"> <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </cc1:ToolkitScriptManager> ...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10252
jinu1996
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...
1
10231
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,...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
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();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.