我获取了GridView
行的值,但是在将数据绑定到DataList
之后。 DataList
无法显示
ASPX
<asp:GridView ID ="gvresults" runat="server"
onselectedindexchanged="gvresults_SelectedIndexChanged">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="Select" Text="Select" />
</Columns>
</asp:GridView>
<asp:DataList ID ="dlresults" runat="server"></asp:DataList>
aspx.cs
protected void gvresults_SelectedIndexChanged(object sender, EventArgs e)
{
string Keywordid = gvresults.SelectedRow.Cells[1].Text;
string val1 = gvresults.SelectedRow.Cells[2].Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("select * from Tbl_keywords where KeywordID ='" + Keywordid + "'",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
dlresults.DataSource = ds;
dlresults.DataBind();
}
答案 0 :(得分:0)
你这样写道:
dlresults.DataSource = ds.Tables[0];
dlresults.DataBind();
dlresults.DataKeyField = "SomeKey";
dlresults.Visible = true;
在你的asp代码中:
<asp:DataList ID ="dlresults" runat="server">
<ItemTemplate>
<asp:Label runat='server' ID='lblItemName' Text='<%# DataBinder.Eval(Container.DataItem, "someVal") %>'>
</asp:Label>
</ItemTemplate>
</asp:DataList>