473,396 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

LinkButton in a datagrid???

Can someone tell me how I do a response.redirect 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 4079
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.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_ItemCommand _
(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.ItemCommand
' Check for the right link button
If e.CommandName = "Select" Then
' Build the redirection URL
Response.Redirect("othersite.aspx?id=" & e.CommandArgument)
End If
End Sub

Function CreateDataSource() 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 _
("DownloadURL", 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 'CreateDataSource

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:BoundColumn DataField="ProductId"
Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="DownloadURL"
Visible="False"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="lnkArticle"
CommandArgument='<%#DataBinder.Eval(Container, "DataItem.ProductId")%>'
Runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Title")%>'
CommandName="Select" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:BD**********************************@microsof t.com...
Can someone tell me how I do a response.redirect 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"
AlternatingItemStyle-BackColor="WhiteSmoke" CssClass="txtArea"
ShowFooter="false" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center" CellPadding="4" Width="50%"
AutoGenerateColumns="False"
BorderStyle="Ridge" BorderWidth="1px" GridLines="Horizontal"
BorderColor="LightGray">
<EditItemStyle BackColor="#EEEEEE"></EditItemStyle>
<AlternatingItemStyle BackColor="WhiteSmoke"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center"
ForeColor="White" BackColor="Black"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="PageId"
Visible="False"></asp:BoundColumn>

<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<img src="../images/page.gif">
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Page">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("header") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("description") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="PageEdit"
CommandArgument='<%#DataBinder.Eval(Container, "DataItem.PageId")%>'
Text='<img border=0 src=../images/edit.gif alt=Edit Page>'
CommandName="Select" Runat="server">
</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="PageProperties"
CommandArgument='<%#DataBinder.Eval(Container, "DataItem.PageId")%>'
Runat="server" Text="<img border=0 src=../images/properties.gif alt=Page
Properties>" CommandName="Properties">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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(ConfigurationSettings.AppSettings("s trConn"))

Dim cmd As New SqlCommand("PageDetails", Myconn)

cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objOfficeName, objID As SqlParameter

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

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

objOfficeName.Direction = ParameterDirection.Input

'objID.Direction = ParameterDirection.Input

objOfficeName.Value = FindOffice()

'objID.Value = 2

Dim myReader As SqlDataReader = cmd.ExecuteReader()

Dim hasRows As Boolean

hasRows = True

DGPages.DataSource = myReader

DGPages.DataBind()

If DGPages.Items.Count = 0 Then

lblNoContent.Visible = True

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

End If

myReader.Close()

Myconn.Close()

End Sub 'Loads Data into Datagrid

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DGPages.ItemCommand

' Check for the right link button

If e.CommandName = "Select" Then

' Build the redirection URL

Response.Redirect("../default.aspx?id=" & e.CommandArgument)

End If

End Sub
Nov 19 '05 #3
Hey Tim,

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

<asp:hyperlinkcolumn DataNavigateUrlField="pageid"
DataNavigateUrlFormatString="destination.aspx?id={ 0}"
DataTextField="PageId"></asp:hyperlinkcolumn>

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:E9**********************************@microsof t.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"
AlternatingItemStyle-BackColor="WhiteSmoke" CssClass="txtArea"
ShowFooter="false" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center" CellPadding="4" Width="50%"
AutoGenerateColumns="False"
BorderStyle="Ridge" BorderWidth="1px" GridLines="Horizontal"
BorderColor="LightGray">
<EditItemStyle BackColor="#EEEEEE"></EditItemStyle>
<AlternatingItemStyle
BackColor="WhiteSmoke"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center"
ForeColor="White" BackColor="Black"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="PageId"
Visible="False"></asp:BoundColumn>

<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<img src="../images/page.gif">
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Page">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("header") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("description") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="PageEdit"
CommandArgument='<%#DataBinder.Eval(Container, "DataItem.PageId")%>'
Text='<img border=0 src=../images/edit.gif alt=Edit Page>'
CommandName="Select" Runat="server">
</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="PageProperties"
CommandArgument='<%#DataBinder.Eval(Container, "DataItem.PageId")%>'
Runat="server" Text="<img border=0 src=../images/properties.gif alt=Page
Properties>" CommandName="Properties">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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(ConfigurationSettings.AppSettings("s trConn"))

Dim cmd As New SqlCommand("PageDetails", Myconn)

cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objOfficeName, objID As SqlParameter

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

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

objOfficeName.Direction = ParameterDirection.Input

'objID.Direction = ParameterDirection.Input

objOfficeName.Value = FindOffice()

'objID.Value = 2

Dim myReader As SqlDataReader = cmd.ExecuteReader()

Dim hasRows As Boolean

hasRows = True

DGPages.DataSource = myReader

DGPages.DataBind()

If DGPages.Items.Count = 0 Then

lblNoContent.Visible = True

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

End If

myReader.Close()

Myconn.Close()

End Sub 'Loads Data into Datagrid

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DGPages.ItemCommand

' Check for the right link button

If e.CommandName = "Select" Then

' Build the redirection URL

Response.Redirect("../default.aspx?id=" & e.CommandArgument)

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:hyperlinkcolumn DataNavigateUrlField="pageid"
DataNavigateUrlFormatString="destination.aspx?id={ 0}"
DataTextField="PageId"></asp:hyperlinkcolumn>

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:E9**********************************@microsof t.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"
AlternatingItemStyle-BackColor="WhiteSmoke" CssClass="txtArea"
ShowFooter="false" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Center" CellPadding="4" Width="50%"
AutoGenerateColumns="False"
BorderStyle="Ridge" BorderWidth="1px" GridLines="Horizontal"
BorderColor="LightGray">
<EditItemStyle BackColor="#EEEEEE"></EditItemStyle>
<AlternatingItemStyle
BackColor="WhiteSmoke"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center"
ForeColor="White" BackColor="Black"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="PageId"
Visible="False"></asp:BoundColumn>

<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<img src="../images/page.gif">
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Page">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("header") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<%# Container.DataItem("description") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="PageEdit"
CommandArgument='<%#DataBinder.Eval(Container, "DataItem.PageId")%>'
Text='<img border=0 src=../images/edit.gif alt=Edit Page>'
CommandName="Select" Runat="server">
</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="PageProperties"
CommandArgument='<%#DataBinder.Eval(Container, "DataItem.PageId")%>'
Runat="server" Text="<img border=0 src=../images/properties.gif alt=Page
Properties>" CommandName="Properties">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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(ConfigurationSettings.AppSettings("s trConn"))

Dim cmd As New SqlCommand("PageDetails", Myconn)

cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objOfficeName, objID As SqlParameter

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

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

objOfficeName.Direction = ParameterDirection.Input

'objID.Direction = ParameterDirection.Input

objOfficeName.Value = FindOffice()

'objID.Value = 2

Dim myReader As SqlDataReader = cmd.ExecuteReader()

Dim hasRows As Boolean

hasRows = True

DGPages.DataSource = myReader

DGPages.DataBind()

If DGPages.Items.Count = 0 Then

lblNoContent.Visible = True

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

End If

myReader.Close()

Myconn.Close()

End Sub 'Loads Data into Datagrid

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DGPages.ItemCommand

' Check for the right link button

If e.CommandName = "Select" Then

' Build the redirection URL

Response.Redirect("../default.aspx?id=" & e.CommandArgument)

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
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
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...
1
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...
1
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...
2
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...
6
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. ...
7
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...
3
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...
5
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
tracyyun
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...
0
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,...

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.