1
Gridview의 버튼 열을 가져 오는 데 문제가 있습니다. DirectoryInfo 개체를 사용하여 파일의 세부 정보를 가져옵니다. 파일 이름과 만든 날짜를 gridview 열에 넣습니다. 세 번째 열은 버튼 열입니다. buttonkeys의 commandName에 "sendcommand"라는 이름의 데이터 키 (Name, CreationTime)를 설정했습니다. 파일 이름을 다른 페이지로 보내고 싶습니다. RowCommand 이벤트에 대한이 코드는 다음과 같습니다.asp.net C# gridview buttons
protected void gvFiles_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
if (e.CommandName == "sendcommand")
{
int index = Convert.ToInt32(e.CommandArgument);
string fileID = ((GridView)sender).DataKeys[index]["Name"].ToString();
Response.Redirect("[email protected]=" + fileID);
}
}
포스트 백을 제외하고는 아무 것도 발생하지 않습니다. 어떻게해야합니까?
<asp:GridView ID="gvFiles" runat="server" Font-Name="Verdana" Font-Names="Verdana"
Width="401px" AutoGenerateColumns="False" BackColor="White"
BorderColor="Black" BorderStyle="Ridge" BorderWidth="2px"
DataKeyNames="Name,CreationTime"
>
<Columns>
<asp:HyperLinkField AccessibleHeaderText="File Name"
DataNavigateUrlFields="Name" DataNavigateUrlFormatString="~\Assets\reports\{0}"
DataTextField="Name" HeaderText="File Name" >
<HeaderStyle BackColor="#0033CC" ForeColor="White" />
</asp:HyperLinkField>
<asp:BoundField AccessibleHeaderText="Date" DataField="CreationTime"
DataFormatString="{0:d}" HeaderText="Date">
<HeaderStyle BackColor="Blue" ForeColor="White" />
</asp:BoundField>
<asp:ButtonField ButtonType="Button" Text="DO Stuff" CommandName="sendcommand"
HeaderText="WHAT?!" />
</Columns>
<AlternatingRowStyle BackColor="#6699FF" />
</asp:GridView>
gridview 자체 (aspx 또는 C#을 생성하는 설정)의 설정을 볼 수 있습니까? –
CommandArgument 속성을 아무 것도 설정하지 않는다고 말하지 않았습니까? 또한,이 이벤트에 대해 gridview가 구독되어 있으며 디버거가 이벤트 내부의 중단 점에 도달 했습니까? –
gvFiles_RowCommand가 호출되지 않도록 GridView의 'OnRowCommand' 속성이 누락되었습니다. –