asp.net动态列Gridview selectedindexchanged未触发

时间:2015-01-10 11:24:54

标签: c# asp.net gridview

我有一个生成动态列的gridview。

我使用了AutoGenerateSelectButton =" True"属性并尝试使用selectedindexchanged上的标签进行测试

        <asp:GridView ID="GridView1" runat="server"
            AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" 
            GridLines="None" 
            onrowdatabound="GridView1_RowDataBound" 
            onselectedindexchanged="GridView1_SelectedIndexChanged" 
            onselectedindexchanging="GridView1_SelectedIndexChanging">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <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>

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    Label1.Text = "Test";
}

它使用gridview,它使用sqldatasource但不能在此gridview上工作。这是我生成列和行的代码

private void BindGrid(List<string> SelectedInfo)
{
    DataTable dt = new DataTable();
    for (int i = 0; i < SelectedInfo.Count; i++)
    {
        dt.Columns.Add(new DataColumn(SelectedInfo[i], typeof(string)));
    }

    List<string[]> InfoList = getInfoList(SelectedInfo);

    for (int i = 0; i < InfoList.Count; i++)
    {
        dt.Rows.Add(InfoList[i]);
    }

    GridView1.DataSource = dt;
    GridView1.DataBind();
}

0 个答案:

没有答案