Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   DataGrid question (http://www.velocityreviews.com/forums/t618715-datagrid-question.html)

brock wade 06-05-2008 05:37 PM

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?

Yankee Imperialist Dog 06-05-2008 06:02 PM

RE: DataGrid question
 
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?
>


the warlock society 06-05-2008 06:09 PM

Re: DataGrid question
 
On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.com> 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?


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;
}
}

brock wade 06-05-2008 06:20 PM

Re: DataGrid question
 
Forgot to mention, I'm using VB.net.

On Jun 5, 2:09*pm, the warlock society <sh...@tlfst.com> wrote:
> On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.com> 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?

>
> 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 -



the warlock society 06-05-2008 06:27 PM

Re: DataGrid question
 
On Jun 5, 2:20*pm, brock wade <brockusw...@yahoo.com> wrote:
> Forgot to mention, I'm using VB.net.
>
> On Jun 5, 2:09*pm, the warlock society <sh...@tlfst.com> wrote:
>
>
>
> > On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.com> 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?

>
> > 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.

Yankee Imperialist Dog 06-05-2008 06:29 PM

Re: DataGrid question
 
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.com> 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?

>
> 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;
> }
> }
>


brock wade 06-06-2008 07:52 PM

Re: DataGrid question
 
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.com> wrote:
> On Jun 5, 2:20*pm, brock wade <brockusw...@yahoo.com> wrote:
>
>
>
>
>
> > Forgot to mention, I'm using VB.net.

>
> > On Jun 5, 2:09*pm, the warlock society <sh...@tlfst.com> wrote:

>
> > > On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.com> 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?

>
> > > 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 -



brock wade 06-09-2008 01:02 PM

Re: DataGrid question
 
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.com> wrote:
> On Jun 5, 2:20*pm, brock wade <brockusw...@yahoo.com> wrote:
>
>
>
>
>
> > Forgot to mention, I'm using VB.net.

>
> > On Jun 5, 2:09*pm, the warlock society <sh...@tlfst.com> wrote:

>
> > > On Jun 5, 1:37 pm, brock wade <brockusw...@yahoo.com> 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?

>
> > > 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 -



brock wade 06-10-2008 08:14 PM

Re: DataGrid question
 
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.com> wrote:
> 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.com> 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?

>
> > 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 -




All times are GMT. The time now is 12:19 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.