473,394 Members | 1,916 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,394 software developers and data experts.

VB.NET code troubleshooting (CommandArgument property during OnItemDataBound event)

i'm trying to set the commandargument property of a buttoncolumn in the
DataGrid ItemBind event. it works fine in one instance, but in the
latest page i've written it doesn't seem to work, and i can't see why.
can anyone tell me why this chunk of code works:

[from File1.aspx]
<asp:datagrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 16px;
POSITION: absolute; TOP: 136px" runat="server" CellPadding="3"
OnItemDataBound="DataGridBindEvent"
OnItemCommand="DataGridCommandEvent" AutoGenerateColumns="False">
<HeaderStyle Font-Bold="True" Wrap="False"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Ad ID">
<ItemTemplate>
<a href="<%# sRentClicksURL %>display.asp?adid=<%#
DataBinder.Eval(Container.DataItem, "Ad ID") %>"
target="new"><%# DataBinder.Eval(Container.DataItem, "Ad
ID") %>
</a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Virtual Tour URL">
<ItemTemplate>
<a href="<%# DataBinder.Eval(Container.DataItem, "Virtual
Tour URL") %>" target="new"><%# DataBinder.Eval
(Container.DataItem, "Virtual Tour URL") %>
</a>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="URLText" Runat="Server" Size="55" Text='<%#
DataBinder.Eval(Container.DataItem, "Virtual Tour URL") %
'>

</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Approve" ButtonType="PushButton"
CommandName="Approve">
</asp:ButtonColumn>
<asp:ButtonColumn Text="Reject" ButtonType="PushButton"
CommandName="Reject">
</asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Save
Edits" CancelText="Cancel Edits" EditText="Edit">
</asp:EditCommandColumn>
</Columns>
</asp:datagrid>

[from File1.aspx.vb]
Protected Sub DataGridBindEvent(ByVal sender As System.Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim tItemType As ListItemType
tItemType = e.Item.ItemType
If tItemType = ListItemType.Header Or tItemType = _
ListItemType.Footer Or tItemType = ListItemType.Separator Then
Exit Sub
End If

Dim oRow As Common.DbDataRecord = CType(e.Item.DataItem, _
Common.DbDataRecord)
Dim sID As String = oRow(0)

Dim oButtonCell1 As TableCell = CType(e.Item.Controls(2), _
TableCell)
Dim oB1 As Button = CType(oButtonCell1.Controls(0), Button)
oB1.CommandArgument = sID

Dim oButtonCell3 As TableCell = CType(e.Item.Controls(3), _
TableCell)
Dim oB3 As Button = CType(oButtonCell3.Controls(0), Button)
oB3.CommandArgument = sID
End Sub
but this chunk doesn't:

[from File2.aspx]
<asp:datagrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 24px;
POSITION: absolute; TOP: 320px" runat="server" Font-Size="Small"
CellPadding="3" Caption="<b>Results</b>" Visible="False"
OnItemDataBound="DataGridBindEvent"
OnItemCommand="DataGridCommandEvent">
<FooterStyle Wrap="False"></FooterStyle>
<SelectedItemStyle Wrap="False"></SelectedItemStyle>
<EditItemStyle Wrap="False"></EditItemStyle>
<AlternatingItemStyle Wrap="False"></AlternatingItemStyle>
<ItemStyle Wrap="False"></ItemStyle>
<HeaderStyle Font-Bold="True" Wrap="False"></HeaderStyle>
<Columns>
<asp:HyperLinkColumn Text="Edit" Target="_blank">
</asp:HyperLinkColumn>
<asp:ButtonColumn Text="Delete" ButtonType="LinkButton"
CommandName="Delete">
</asp:ButtonColumn>
</Columns>
</asp:datagrid>

? thanks for any help,

jason

Nov 19 '05 #1
2 2654
If it is giving out any error, please let me know. One more thing is, check
whether you get the right button control to set the command argument property.

"jason" wrote:
i'm trying to set the commandargument property of a buttoncolumn in the
DataGrid ItemBind event. it works fine in one instance, but in the
latest page i've written it doesn't seem to work, and i can't see why.
can anyone tell me why this chunk of code works:

[from File1.aspx]
<asp:datagrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 16px;
POSITION: absolute; TOP: 136px" runat="server" CellPadding="3"
OnItemDataBound="DataGridBindEvent"
OnItemCommand="DataGridCommandEvent" AutoGenerateColumns="False">
<HeaderStyle Font-Bold="True" Wrap="False"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Ad ID">
<ItemTemplate>
<a href="<%# sRentClicksURL %>display.asp?adid=<%#
DataBinder.Eval(Container.DataItem, "Ad ID") %>"
target="new"><%# DataBinder.Eval(Container.DataItem, "Ad
ID") %>
</a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Virtual Tour URL">
<ItemTemplate>
<a href="<%# DataBinder.Eval(Container.DataItem, "Virtual
Tour URL") %>" target="new"><%# DataBinder.Eval
(Container.DataItem, "Virtual Tour URL") %>
</a>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="URLText" Runat="Server" Size="55" Text='<%#
DataBinder.Eval(Container.DataItem, "Virtual Tour URL") %
>'>

</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Approve" ButtonType="PushButton"
CommandName="Approve">
</asp:ButtonColumn>
<asp:ButtonColumn Text="Reject" ButtonType="PushButton"
CommandName="Reject">
</asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Save
Edits" CancelText="Cancel Edits" EditText="Edit">
</asp:EditCommandColumn>
</Columns>
</asp:datagrid>

[from File1.aspx.vb]
Protected Sub DataGridBindEvent(ByVal sender As System.Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim tItemType As ListItemType
tItemType = e.Item.ItemType
If tItemType = ListItemType.Header Or tItemType = _
ListItemType.Footer Or tItemType = ListItemType.Separator Then
Exit Sub
End If

Dim oRow As Common.DbDataRecord = CType(e.Item.DataItem, _
Common.DbDataRecord)
Dim sID As String = oRow(0)

Dim oButtonCell1 As TableCell = CType(e.Item.Controls(2), _
TableCell)
Dim oB1 As Button = CType(oButtonCell1.Controls(0), Button)
oB1.CommandArgument = sID

Dim oButtonCell3 As TableCell = CType(e.Item.Controls(3), _
TableCell)
Dim oB3 As Button = CType(oButtonCell3.Controls(0), Button)
oB3.CommandArgument = sID
End Sub
but this chunk doesn't:

[from File2.aspx]
<asp:datagrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 24px;
POSITION: absolute; TOP: 320px" runat="server" Font-Size="Small"
CellPadding="3" Caption="<b>Results</b>" Visible="False"
OnItemDataBound="DataGridBindEvent"
OnItemCommand="DataGridCommandEvent">
<FooterStyle Wrap="False"></FooterStyle>
<SelectedItemStyle Wrap="False"></SelectedItemStyle>
<EditItemStyle Wrap="False"></EditItemStyle>
<AlternatingItemStyle Wrap="False"></AlternatingItemStyle>
<ItemStyle Wrap="False"></ItemStyle>
<HeaderStyle Font-Bold="True" Wrap="False"></HeaderStyle>
<Columns>
<asp:HyperLinkColumn Text="Edit" Target="_blank">
</asp:HyperLinkColumn>
<asp:ButtonColumn Text="Delete" ButtonType="LinkButton"
CommandName="Delete">
</asp:ButtonColumn>
</Columns>
</asp:datagrid>

? thanks for any help,

jason

Nov 19 '05 #2
thanks for the reply. the run-time error is an invalid cast exception
on the line:

Dim oB As Button = CType(oButtonCell.Controls(0), Button)

i'm fairly sure that's the only control in the cell, because it is a
buttoncolumn with no other elements, just like the example above that
is working. if there are other controls in the cell, i have no idea
what they would be. but still, your prognosis makes sense, given the
error message. Control(0) doesn't seem to be a button during run time.
i'll see if i can spit out the types of each of the controls to see
what's going on.

thanks,

jason

Nov 19 '05 #3

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

Similar topics

1
by: Stephen | last post by:
Hey Everyone, I have a problem with a web application due to the use of both client-side and server side script on the on-click event of a button. The client side script runs first as expected...
1
by: Stephen | last post by:
Hey All, I have a problem with a web application due to the use of both client-side and server side script on the on-click event of a button. The client side script runs first as expected however...
2
by: Benjamin Joldersma | last post by:
Hello all, My basic problem is that my LinkButton does not support a data bound CommandArgument property under certain cases. The intent is to filter my datagrid based on a specific row's...
2
by: charliewest | last post by:
In the datagrid ButtonColumn, for both the pressButton and linkButton, there is no CommandArgument property. My question is: How do i go about programming events using the commandName without...
1
by: Fabrice | last post by:
Hello Is it possible to modify CommandArgument property of a LinkButton from vb class (code behind). So, this is my control in my .aspx page : <asp:LinkButton id="strTd"...
2
by: Fabrice | last post by:
Hello, First, thanks to felix for his answer. But :-( , I'm feeling newbie :! I' don't understand all the situation. The trouble : Always in the road whith my Datagrid and my ItemTemplate...
2
by: David | last post by:
I have a template field in a GridView that contains two ImageButtons. When the user clicks one of the buttons, the GridView's RowCommand event is fired and I can get the CommandName. All that is...
2
by: RN1 | last post by:
Suppose I have a LinkButton whose Text is the name of a user (which is being retrieved from a database). What I want is when I click this LinkButton, I want the e-mail id of the user (which will be...
1
by: beardog | last post by:
I've got a question for the gurus out there. I'm trying to create an IF conditional inside my aspx page that reads the state of a boolean in the code behind. Here's the basic ASP: ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.