Datagrid button

  • Thread starter Thread starter brock wade
  • Start date Start date
B

brock wade

I have a Datagrid that is working fine displying my records, but I'm
trying to program buttons
on each record line to launch another web page that shows all the
details for the product:

<asp:datagrid id="dgProducts" runat="server">
<asp:ButtonColumn Text="Details" CommandName="Details"
ButtonType="PushButton"></asp:ButtonColumn>
</asp:datagrid>


Should I go to my code-behind to do something like this?:


Sub detailsClicked(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Response.Redirect("www.mysite.com\details.aspx")
End Sub


If so how can I pass the chosen record's key information into the new
page to pickup the details?
 
I have a Datagrid that is working fine displying my records, but I'm
trying to program buttons
on each record line to launch another web page that shows all the
details for the product:

<asp:datagrid id="dgProducts" runat="server">
<asp:ButtonColumn Text="Details" CommandName="Details"
ButtonType="PushButton"></asp:ButtonColumn>
</asp:datagrid>

Should I go to my code-behind to do something like this?:

Sub detailsClicked(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Response.Redirect("www.mysite.com\details.aspx")
End Sub

If so how can I pass the chosen record's key information into the new
page to pickup the details?

Hi

You are taking about master detail view of course.
check out this tutorial... i believe this is what you want...
http://www.asp.net/learn/data-access/tutorial-10-vb.aspx

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 
Thanks for the link. It looks good. Let me make sure I'm on the
correct path here. I have a DataGrid and the only change I've made so
far is adding "DataTextField="Key"

<asp:datagrid id="dgProducts" runat="server">
<asp:ButtonColumn Text="Details" CommandName="Details"
DataTextField="Key"
ButtonType="PushButton"></asp:ButtonColumn>
</asp:datagrid>

The reason I used "Key" is the way the code-behind ia setup (note the
dr.Key):

Private Sub SetListViewItem(ByVal dr As Employee, ByVal dt As
DataTable, ByVal count As Integer)
If count = 0 Then
dt.Columns.Add("Emp #")
dt.Columns.Add("Last Name")
dt.Columns.Add("First Name")
dt.Columns.Add("Title")
End If
Dim EmpPos As Action = (New
ActionBroker).GetActionCurrent(dr.Key, Today, Global.UserName,
Global.UserPassword, Global.appDataSource)
Dim employee As DataRow = dt.NewRow
employee("Emp #") = dr.Key
employee("Last Name") = dr.LastName
employee("First Name") = dr.FirstName
employee("Title") = EmpPos.WorkAgainstInfo.Title
dt.Rows.Add(employee)
End Sub 'SetListViewItem

When I run the page though it says that "A field or property with the
name 'Key' was not found on the selected datasource."

Any ideas?
 
Back
Top