UI機能:GridView
いくつかの列があります。最も重要な列はPcCodestring
で、各行の値を示します。
予想:そのPcCode列の行からセルの1つをクリックすると、別のセルGridView
が表示されます。ただし、asp:LinkButton
セルにaを使用しようとすると、うまくいきません。セル内のRowCommand
aをクリックしてもトリガーされません。私はどこで間違ったことをしているのですか?期待される機能をどのように実現できますか?初心者を助けてくれてありがとう。 asp:LinkButton
GridView
次のコードでは、を取得しRowIndex
て通過させ、CommandArgument
を使用しようとしていましたCommandName
。
.aspxコード
<asp:GridView ID="_UIProfitcenterTotalGridView" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="22" ShowFooter="True" AutoGenerateColumns="False"
DataKeyNames="ProfitcenterCode" EnableViewState="False"
OnRowDataBound="_UIProfitcenterTotalGridView_RowDataBound"
OnPageIndexChanging="_UIProfitcenterTotalGridView_PageIndexChanging"
OnRowCommand="_UIProfitcenterTotalGridView_OnRowCommand">
<Columns>
<asp:TemplateField HeaderText="PcCode" InsertVisible="False"
ShowHeader="False" SortExpression="ProfitcenterCode" FooterText="Total" FooterStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:LinkButton ID="_UIPCCodeLinkButton" runat="server" Text='<%# Eval("ProfitcenterCode") %>'
CommandName="Select"
CommandArgument='<%# ((GridViewRow) Container).RowIndex %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
...
aspx.csのコードビハインド
protected void _UIProfitcenterTotalGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = _UIProfitcenterTotalGridView.Rows[index];
string ProfitcenterCode = _UIProfitcenterTotalGridView.DataKeys[_UIProfitcenterTotalGridView.SelectedIndex].Values["ProfitcenterCode"].ToString();
}
}
行が選択されたら、選択した行の値を文字列として取得し、listitemと比較して、新しいGridViewを表示する必要があります。
試してみました
Link_Button_Click(オブジェクト送信者、EventArgs e)および以下を使用しましたが、失敗しました。
protected void _UIProfitcenterTotalGridView_RowCommand(object sender、GridViewCommandEventArgs e){if(e.CommandName == "Select"){string ProfitcenterCode =((GridViewRow)(((LinkButton)e.CommandSource).NamingContainer))。Cells [2] .Text ; }}