473,402 Members | 2,072 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,402 software developers and data experts.

DataGrid question

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?
Jun 27 '08 #1
8 1240
You can do it that way and bind the key you need to display details to the
EventArgument.
you can just add a hyperlink to the datagrind and bind the key to the url
similar to
above.
Or if you want to get creative you can set the post back url on the button
to your detail page. just be careful of circular references. (i can give you
an artical if you want to know how to do that)
--
Share The Knowledge. I need all the help I can get and so do you!
"brock wade" wrote:
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?
Jun 27 '08 #2
On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.comwrote:
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?
Brock

In the Itemdatabound event you'll want to set the button's
commandargument to the chosen record's key.
Also set the button's commandname to something like "redirect" or
something that associates that commandname with the event you're
firing.

You're going to capture the button's click event in the OnItemCommand
event of the datagrid. Make a simple select case statement that
checks the command name's property of the button - inside that
statement you'll check the commandarguement to get the value.

here's an example:

protected void ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
ImageButton btn =
(ImageButton)e.Item.FindControl("myImageButton");
btn.CommandName = "MyCommandName";
btn.CommandArguement = drv["ID"].ToString();
}
}

then the itemcommand will look like this:

protected void ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
switch(e.CommandName)
{
default:
break;
case "MyCommandName":
Response.Redirect("www.mysite.com\" +
e.CommandArguement)
break;
}
}
Jun 27 '08 #3
Forgot to mention, I'm using VB.net.

On Jun 5, 2:09*pm, the warlock society <sh...@tlfst.comwrote:
On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.comwrote:


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?

Brock

In the Itemdatabound event you'll want to set the button's
commandargument to the chosen record's key.
Also set the button's commandname to something like "redirect" or
something that associates that commandname with the event you're
firing.

You're going to capture the button's click event in the OnItemCommand
event of the datagrid. *Make a simple select case statement that
checks the command name's property of the button - inside that
statement you'll check the commandarguement to get the value.

here's an example:

protected void ItemDataBound(object sender, DataGridItemEventArgs e)
{
* * *if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem)
* * *{
* * * * *DataRowView drv = (DataRowView)e.Item.DataItem;
* * * * *ImageButton btn =
(ImageButton)e.Item.FindControl("myImageButton");
* * * * *btn.CommandName = "MyCommandName";
* * * * *btn.CommandArguement = drv["ID"].ToString();
* * *}

}

then the itemcommand will look like this:

protected void ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
* * *switch(e.CommandName)
* * *{
* * * * *default:
* * * * * * * break;
* * * * *case "MyCommandName":
* * * * * * * Response.Redirect("www.mysite.com\" +
e.CommandArguement)
* * * * * * * break;
* * *}

}- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Jun 27 '08 #4
On Jun 5, 2:20*pm, brock wade <brockusw...@yahoo.comwrote:
Forgot to mention, I'm using VB.net.

On Jun 5, 2:09*pm, the warlock society <sh...@tlfst.comwrote:
On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.comwrote:
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?
Brock
In the Itemdatabound event you'll want to set the button's
commandargument to the chosen record's key.
Also set the button's commandname to something like "redirect" or
something that associates that commandname with the event you're
firing.
You're going to capture the button's click event in the OnItemCommand
event of the datagrid. *Make a simple select case statement that
checks the command name's property of the button - inside that
statement you'll check the commandarguement to get the value.
here's an example:
protected void ItemDataBound(object sender, DataGridItemEventArgs e)
{
* * *if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem)
* * *{
* * * * *DataRowView drv = (DataRowView)e.Item.DataItem;
* * * * *ImageButton btn =
(ImageButton)e.Item.FindControl("myImageButton");
* * * * *btn.CommandName = "MyCommandName";
* * * * *btn.CommandArguement = drv["ID"].ToString();
* * *}
}
then the itemcommand will look like this:
protected void ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
* * *switch(e.CommandName)
* * *{
* * * * *default:
* * * * * * * break;
* * * * *case "MyCommandName":
* * * * * * * Response.Redirect("www.mysite.com\" +
e.CommandArguement)
* * * * * * * break;
* * *}
}- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
heh well I could translate it to vb.net for you but honestly there
isnt much difference. The concepts are exactly the same - the
difference is merely syntactical.

If you're having a problem deciphering c# you can just copy and paste
it into a c#/vb.net translator - there's a handful of them on the web.
Jun 27 '08 #5
if it's a simple key you should be able to bind it directly without going to
the event.
Use the designer and bind the key by selecting the button and selection the
data item you want.
--
Share The Knowledge. I need all the help I can get and so do you!
"the warlock society" wrote:
On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.comwrote:
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?

Brock

In the Itemdatabound event you'll want to set the button's
commandargument to the chosen record's key.
Also set the button's commandname to something like "redirect" or
something that associates that commandname with the event you're
firing.

You're going to capture the button's click event in the OnItemCommand
event of the datagrid. Make a simple select case statement that
checks the command name's property of the button - inside that
statement you'll check the commandarguement to get the value.

here's an example:

protected void ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
ImageButton btn =
(ImageButton)e.Item.FindControl("myImageButton");
btn.CommandName = "MyCommandName";
btn.CommandArguement = drv["ID"].ToString();
}
}

then the itemcommand will look like this:

protected void ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
switch(e.CommandName)
{
default:
break;
case "MyCommandName":
Response.Redirect("www.mysite.com\" +
e.CommandArguement)
break;
}
}
Jun 27 '08 #6
Thanks for the translator tip - I'm a newbi in ASP.net so I've got a
lot to learn. I got the basic translation to place into my code-
behind. I do have a few questions to make sure I'm following the logic
here. For one thing the compiler does not like the "e.CommandArgument"
even though Intellisense lists it as a choice "Option Strict On
disallows implicit conversions from 'System.Object' to Boolean'. I'm
assuming the "Response.Redirect("c:\inetpub\wwwroot\HR_Reportin gTool
\HR_ReportingToolClient_1\Details.aspx"" +", e.CommandArgument)" is
basically correct for the redirect since my application itself resides
at "c:\inetpub\wwwroot\HR_ReportingTool\HR_ReportingT oolClient_1".
Plus I hope I'm referencing the Button name correctly between the code-
behind and the html as "Details":

' ****** PARTIAL SAMPLE OF THE
CODE-BEHIND ******
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
lblWelcome.Text = "Hello " & Global.UserSecurity.Fname.Trim &
" " & Global.UserSecurity.Lname
Dim act As Action
Dim pos As Position
Dim empname As String
Dim lvi As ListItem
Dim Employee As Employee
Dim empcount As Integer
act = (New
ActionBroker).GetActionCurrent(Global.UserSecurity .EmpId, Today,
Global.UserName, Global.UserPassword, Global.appDataSource)
pos = (New PositionBroker).GetPosition(act.PositionID,
Global.UserName, Global.UserPassword, Global.appDataSource)
m_department = pos.Department.Name
Dim emps As Employees = (New
EmployeeBroker).GetCurrentEmployeesByDepartment(m_ department,
Global.UserName, Global.UserPassword, Global.appDataSource)
Dim dt As New DataTable
Dim count As Integer = 0
For Each emp As Employee In emps
SetListViewItem(emp, dt, count)
count = count + 1
Next
dgEmployees.DataSource = dt
dgEmployees.DataBind()

End Sub

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

Protected Sub ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If ((e.Item.ItemType = ListItemType.Item) _
OrElse (e.Item.ItemType =
ListItemType.AlternatingItem)) Then
Dim drv As DataRowView = CType(e.Item.DataItem,
DataRowView)
Dim btn As ImageButton =
CType(e.Item.FindControl("Details"), ImageButton)
btn.CommandName = "Details"
btn.CommandArgument = drv("Key").ToString
End If
End Sub

Protected Sub OnItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs )
Select Case (e.CommandName)
Case "Details"
Response.Redirect("c:\inetpub\wwwroot\HR_Reporting Tool
\HR_ReportingToolClient_1\Details.aspx"" +", e.CommandArgument)
End Select
End Sub
' ****** END PARTIAL SAMPLE OF
THE CODE-BEHIND ******

' ****** HTML ******

<asp:datagrid id="dgEmployees" runat="server" lowSorting="True"
<Columns>
<asp:ButtonColumn Text="Details" CommandName="Details"
ButtonType="PushButton"></asp:ButtonColumn>
</Columns>
</asp:datagrid>

Of course I am a ways away from creating the Employees Detail .aspx
and about 20 text boxes hopefully to be filled with the balance of the
Employee fields.

Thanks!!!! Brockus


On Jun 5, 2:27*pm, the warlock society <sh...@tlfst.comwrote:
On Jun 5, 2:20*pm, brock wade <brockusw...@yahoo.comwrote:


Forgot to mention, I'm using VB.net.
On Jun 5, 2:09*pm, the warlock society <sh...@tlfst.comwrote:
On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.comwrote:
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?
Brock
In the Itemdatabound event you'll want to set the button's
commandargument to the chosen record's key.
Also set the button's commandname to something like "redirect" or
something that associates that commandname with the event you're
firing.
You're going to capture the button's click event in the OnItemCommand
event of the datagrid. *Make a simple select case statement that
checks the command name's property of the button - inside that
statement you'll check the commandarguement to get the value.
here's an example:
protected void ItemDataBound(object sender, DataGridItemEventArgs e)
{
* * *if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem)
* * *{
* * * * *DataRowView drv = (DataRowView)e.Item.DataItem;
* * * * *ImageButton btn =
(ImageButton)e.Item.FindControl("myImageButton");
* * * * *btn.CommandName = "MyCommandName";
* * * * *btn.CommandArguement = drv["ID"].ToString();
* * *}
}
then the itemcommand will look like this:
protected void ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
* * *switch(e.CommandName)
* * *{
* * * * *default:
* * * * * * * break;
* * * * *case "MyCommandName":
* * * * * * * Response.Redirect("www.mysite.com\" +
e.CommandArguement)
* * * * * * * break;
* * *}
}- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -

heh well I could translate it to vb.net for you but honestly there
isnt much difference. *The concepts are exactly the same - the
difference is merely syntactical.

If you're having a problem deciphering c# you can just copy and paste
it into a c#/vb.net translator - there's a handful of them on the web.- Hide quoted text -

- Show quoted text -
Jun 27 '08 #7
Thanks for the translator tip - I'm a newbi in ASP.net so I've got a
lot to learn. I got the basic translation to place into my code-
behind. I do have a few questions to make sure I'm following the
logic
here. For one thing the compiler does not like the
"e.CommandArgument"
even though Intellisense lists it as a choice "Option Strict On
disallows implicit conversions from 'System.Object' to Boolean'. I'm
assuming the "Response.Redirect("c:\inetpub\wwwroot\HR_Reportin gTool
\HR_ReportingToolClient_1\Details.aspx"" +", e.CommandArgument)" is
basically correct for the redirect since my application itself
resides
at "c:\inetpub\wwwroot\HR_ReportingTool\HR_ReportingT oolClient_1".
Plus I hope I'm referencing the Button name correctly between the
code-
behind and the html as "Details":

' ****** PARTIAL SAMPLE OF THE
CODE-BEHIND ******
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
lblWelcome.Text = "Hello " & Global.UserSecurity.Fname.Trim &
" " & Global.UserSecurity.Lname
Dim act As Action
Dim pos As Position
Dim empname As String
Dim lvi As ListItem
Dim Employee As Employee
Dim empcount As Integer
act = (New
ActionBroker).GetActionCurrent(Global.UserSecurity .EmpId, Today,
Global.UserName, Global.UserPassword, Global.appDataSource)
pos = (New PositionBroker).GetPosition(act.PositionID,
Global.UserName, Global.UserPassword, Global.appDataSource)
m_department = pos.Department.Name
Dim emps As Employees = (New
EmployeeBroker).GetCurrentEmployeesByDepartment(m_ department,
Global.UserName, Global.UserPassword, Global.appDataSource)
Dim dt As New DataTable
Dim count As Integer = 0
For Each emp As Employee In emps
SetListViewItem(emp, dt, count)
count = count + 1
Next
dgEmployees.DataSource = dt
dgEmployees.DataBind()
End Sub
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
Protected Sub ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
If ((e.Item.ItemType = ListItemType.Item) _
OrElse (e.Item.ItemType =
ListItemType.AlternatingItem)) Then
Dim drv As DataRowView = CType(e.Item.DataItem,
DataRowView)
Dim btn As ImageButton =
CType(e.Item.FindControl("Details"), ImageButton)
btn.CommandName = "Details"
btn.CommandArgument = drv("Key").ToString
End If
End Sub
Protected Sub OnItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs )
Select Case (e.CommandName)
Case "Details"
Response.Redirect("c:\inetpub\wwwroot
\HR_ReportingTool
\HR_ReportingToolClient_1\Details.aspx"" +", e.CommandArgument)
End Select
End Sub
' ****** END PARTIAL SAMPLE OF
THE CODE-BEHIND ******
' ****** HTML ******
<asp:datagrid id="dgEmployees" runat="server" lowSorting="True"
<Columns>
<asp:ButtonColumn Text="Details"
CommandName="Details"
ButtonType="PushButton"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
Of course I am a ways away from creating the Employees Detail .aspx
and about 20 text boxes hopefully to be filled with the balance of
the
Employee fields.
Thanks!!!! Brockus


On Jun 5, 2:27*pm, the warlock society <sh...@tlfst.comwrote:
On Jun 5, 2:20*pm, brock wade <brockusw...@yahoo.comwrote:


Forgot to mention, I'm using VB.net.
On Jun 5, 2:09*pm, the warlock society <sh...@tlfst.comwrote:
On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.comwrote:
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?
Brock
In the Itemdatabound event you'll want to set the button's
commandargument to the chosen record's key.
Also set the button's commandname to something like "redirect" or
something that associates that commandname with the event you're
firing.
You're going to capture the button's click event in the OnItemCommand
event of the datagrid. *Make a simple select case statement that
checks the command name's property of the button - inside that
statement you'll check the commandarguement to get the value.
here's an example:
protected void ItemDataBound(object sender, DataGridItemEventArgs e)
{
* * *if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem)
* * *{
* * * * *DataRowView drv = (DataRowView)e.Item.DataItem;
* * * * *ImageButton btn =
(ImageButton)e.Item.FindControl("myImageButton");
* * * * *btn.CommandName = "MyCommandName";
* * * * *btn.CommandArguement = drv["ID"].ToString();
* * *}
}
then the itemcommand will look like this:
protected void ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
* * *switch(e.CommandName)
* * *{
* * * * *default:
* * * * * * * break;
* * * * *case "MyCommandName":
* * * * * * * Response.Redirect("www.mysite.com\" +
e.CommandArguement)
* * * * * * * break;
* * *}
}- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -

heh well I could translate it to vb.net for you but honestly there
isnt much difference. *The concepts are exactly the same - the
difference is merely syntactical.

If you're having a problem deciphering c# you can just copy and paste
it into a c#/vb.net translator - there's a handful of them on the web.- Hide quoted text -

- Show quoted text -
Jun 27 '08 #8
Sould I be binding the actual DataGrid to the DataSource using "Simple
Binding" which gives me the Option of "Page"? If so or not how do I
launch then my Details.aspx and pickup the fileds on that screen which
correspond to the reocord chosen by the button specific to the
datarow?
Thanks!
On Jun 5, 2:29*pm, Yankee Imperialist Dog
<YankeeImperialist...@discussions.microsoft.comwro te:
if it's a simple key you should be able to bind it directly without going to
the event.
Use the designer and bind the key by selecting the button and selection the
data item you want.
--
Share The Knowledge. I need all the help I can get and so do you!

"the warlock society" wrote:
On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.comwrote:
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?
Brock
In the Itemdatabound event you'll want to set the button's
commandargument to the chosen record's key.
Also set the button's commandname to something like "redirect" or
something that associates that commandname with the event you're
firing.
You're going to capture the button's click event in the OnItemCommand
event of the datagrid. *Make a simple select case statement that
checks the command name's property of the button - inside that
statement you'll check the commandarguement to get the value.
here's an example:
protected void ItemDataBound(object sender, DataGridItemEventArgs e)
{
* * *if (e.Item.ItemType== ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem)
* * *{
* * * * *DataRowView drv = (DataRowView)e.Item.DataItem;
* * * * *ImageButton btn =
(ImageButton)e.Item.FindControl("myImageButton");
* * * * *btn.CommandName = "MyCommandName";
* * * * *btn.CommandArguement = drv["ID"].ToString();
* * *}
}
then the itemcommand will look like this:
protected void ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
* * *switch(e.CommandName)
* * *{
* * * * *default:
* * * * * * * break;
* * * * *case "MyCommandName":
* * * * * * * Response.Redirect("www.mysite.com\" +
e.CommandArguement)
* * * * * * * break;
* * *}
}- Hide quoted text -

- Show quoted text -
Jun 27 '08 #9

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

Similar topics

2
by: magister | last post by:
Hello, I have xml like this.... <test> <question>sdfsa</question> <section><question>43ga</question> <question>asdf</question> </test>
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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,...
0
isladogs
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...

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.