我有一个sql数据集gridview表,它显示数据库中的值。我试图将我的commandargument指向我的SQL数据集中的compName变量(如下面的代码中所示),但我一直收到以下错误:
" DataBinding:' System.Data.DataRowView'不包含名称为' compName'。"
的媒体资源我的C#代码:
protected void searchTheDB()
{
string s = "SELECT compName As 'Company/Organization Name', btcAddr As 'Bitcoin Address', Premium_User as 'Premium User'," +
"upvote as 'Upvotes',downvote As 'Downvotes' FROM clientDataTable WHERE compName LIKE '%" + searchBox.Text + "%'";
try
{
SqlConnection forSearch = new SqlConnection(connectionString);
SqlDataAdapter search = new SqlDataAdapter(s, forSearch);
DataSet dB = new DataSet();
search.Fill(dB);
searchGridView.DataSource = dB;
searchGridView.DataBind();
searchBox.Text = String.Empty;
}
catch (SqlException exp)
{
throw new InvalidOperationException("Sorry, the website is experiencing difficulties, please try again, error: ", exp);
}
}
asp.net代码:
<asp:GridView ID="searchGridView" runat="server" CellPadding="10" ForeColor="#333333" GridLines="None" Height="161px" Width="935px" CellSpacing="5" HorizontalAlign="Justify" BorderStyle="Solid" OnRowCommand="searchGridView_RowCommand">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="DownButton" runat="server" CommandName="Upvote" CommandArgument='<%#Eval("compName")%>' Text="Upvote"> </asp:Button>
<asp:Button ID="UpButton" runat="server" CommandName="Downvote" CommandArgument='<%#Eval("compName")%>' Text="Downvote"> </asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
非常感谢你的帮助!