Gridview rowcommand中的输入字符串格式不正确
我有一个gridview,其中所有控件都位于单个templatefield中,如下所示:Gridview rowcommand中的输入字符串格式不正确,gridview,rowcommand,Gridview,Rowcommand,我有一个gridview,其中所有控件都位于单个templatefield中,如下所示: <asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="False" BorderWidth="1px" BorderColor="#CCCCCC" DataKeyNames="RegistrationId" Width="476px" DataSourceID="SqlDataSource1"
<asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="False" BorderWidth="1px" BorderColor="#CCCCCC" DataKeyNames="RegistrationId" Width="476px" DataSourceID="SqlDataSource1" ShowHeader="False" AllowPaging="True" CssClass="auto-style89" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table cellpadding="0" cellspacing="0" class="auto-style4">
<tr>
<td class="auto-style56" style="vertical-align:top" rowspan="3">
<asp:Image ID="Image1" runat="server" Width="100px" Height="100px" ImageUrl='<%# Bind("LogoPath") %>' style="border: 3px groove #666666; padding: 2px;" />
</td>
<td colspan="2" style="background-color: #B22222">
<asp:Label ID="lblBusinessName" runat="server" style="font-size: large; color: #FFFFFF; font-weight: 700;" Text='<%# Bind("BusinessName") %>'></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style81">
<asp:Label ID="lblAddress" runat="server" Text='<%# Bind("StreetAddress") %>' style="color: #6699FF; font-size: small;"></asp:Label>
|
<asp:Label ID="lblCity" runat="server" Text='<%# Bind("City") %>' style="color: #6699FF; font-size: small;"></asp:Label>
-
<asp:Label ID="lblZipCode" runat="server" Text='<%# Bind("ZipCode") %>' style="color: #6699FF; font-size: small;"></asp:Label>
|
<asp:Label ID="lblStates" runat="server" Text='<%# Bind("States") %>' style="color: #6699FF; font-size: small;"></asp:Label>
</td>
<td class="auto-style82">
<asp:Button ID="btnMore" runat="server" CommandName="Select" BackColor="#3366FF" ForeColor="White" Text="More Info" style="border-style: groove; border-color: #666666; padding: 2px; background-color: #808080; font-weight: 700;" />
</td>
</tr>
<tr>
<td class="auto-style17"> <span class="auto-style57">Phone No</span>:
<asp:Label ID="lblContactNo" runat="server" Text='<%# Bind("ContactNo") %>' style="font-size: small"></asp:Label>
<br /> <span class="auto-style57">Website</span>:
<asp:Label ID="lblWebsite" runat="server" Text='<%# Bind("Website") %>' style="font-size: small"></asp:Label>
</td>
<td style="text-align: center" class="auto-style18"><span class="auto-style57"><strong>Reviews</strong></span>(0)</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我在下面的行中得到错误:
int index = Convert.ToInt32(e.CommandArgument);
这里有什么问题吗?是因为我使用的是按钮而不是按钮字段。不过我只是猜测。我知道CommandArgue为null,但如何更正它?在代码中实际获取按钮之前,需要声明按钮的命令参数。 像这样更改按钮的声明
<asp:Button ID="btnMore" runat="server" CommandName="Select" BackColor="#3366FF" ForeColor="White" Text="More Info" style="border-style: groove; border-color: #666666; padding: 2px; background-color: #808080; font-weight: 700;" CommandArgument='<%# Bind("RegistrationId") %>' />
add CommandArgument=''/>@AGuyCalledGerald会话仍然会给我一个不想要的结果,即System.Web.UI.WebControls.Label会话仍然会给我一个不想要的结果,即System.Web.UI.WebControls.Label
<asp:Button ID="btnMore" runat="server" CommandName="Select" BackColor="#3366FF" ForeColor="White" Text="More Info" style="border-style: groove; border-color: #666666; padding: 2px; background-color: #808080; font-weight: 700;" CommandArgument='<%# Bind("RegistrationId") %>' />