0

我有一个网格视图

<asp:GridView ID="wbsdataGV1" runat="server" Width="790px" AutoGenerateColumns="False"
    OnSelectedIndexChanged="wbsdataGV1_SelectionChanged" DataKeyNames="WBSCode">
    <Columns>

    <asp:TemplateField HeaderText="WBS Code">
         <ItemTemplate>
              <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("WBSCode") %>'></asp:LinkButton>
         </ItemTemplate>
         <ControlStyle Width="100px" />
         <ItemStyle BorderStyle="Solid" BorderWidth="1px" />
         </asp:TemplateField>
    <asp:TemplateField HeaderText="Description">
    <ItemTemplate>
         <asp:TextBox ID="TextBox40" runat="server" Text='<%# Eval("Description") %>' ReadOnly="true"
                                                    Width="300px">
          </asp:TextBox>
      </ItemTemplate>
      <ControlStyle Width="300px" />
      <ItemStyle BorderStyle="Solid" BorderWidth="1px" />
   </asp:TemplateField>
   <asp:TemplateField HeaderText="Territory Code">
       <ItemTemplate>
          <asp:Label ID="Label45" runat="server" Text='<%# Eval("TerritoryCode") %>'></asp:Label>
       </ItemTemplate>
       <ControlStyle Width="100px" />
       <ItemStyle BorderStyle="Solid" BorderWidth="1px" />
   </asp:TemplateField>
   <asp:TemplateField HeaderText="Amount">
      <ItemTemplate>
           <asp:Label ID="Label46" runat="server" Text='<%# Eval("AmountReleased") %>'></asp:Label>
      </ItemTemplate>
      <ControlStyle Width="100px" />
      <ItemStyle BorderStyle="Solid" BorderWidth="1px" />
   </asp:TemplateField>
   </Columns>
   <HeaderStyle BackColor="Wheat" BorderStyle="Solid" BorderWidth="1px" />
   <RowStyle BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" 
</asp:GridView>

现在在链接按钮中,我想单击它并在同一页面中检索该行的数据并显示它...

我在用

protected void wbsdataGV1_SelectionChanged(object sender, EventArgs e)
{
    string rowID = (string)this.wbsdataGV1.SelectedDataKey.Value;
    con.Open();
    SqlCommand cmd = new SqlCommand(" select WBSCode,Description,TerritoryCode,AmountReleased from WBS where WBSCode='"+rowID+"'");
    cmd.Connection = con;
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
        wbssearchdata1.DataSource = dt;
        wbssearchdata1.DataBind();
    }

    con.Close();
}

这段代码,但它没有在点击时触发..所以我该如何解决这个..有什么帮助吗?

4

1 回答 1

1

从您的代码中,我看不到您指定触发 SelectedIndexChanged 事件的按钮的任何位置。你需要做这些

<asp:GridView OnSelectedIndexChanged="wbsdataGV1_SelectionChanged"  
              AutoGenerateSelectButton="true" />

或者

<asp:GridView OnSelectedIndexChanged="wbsdataGV1_SelectionChanged">
<Columns>
   <asp:CommandField ShowSelectButton="true" />
</Columns>
</asp:GridView>

或者

   <asp:GridView OnSelectedIndexChanged="wbsdataGV1_SelectionChanged">
   <Columns>
    <asp:TemplateField>
    <ItemTemplate>
        <asp:LinkButton runat="server" ID="Selecting" CommandName="Select" Text="Select Row"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
   </Columns>
   </asp:GridView>
于 2012-11-07T12:51:44.623 回答