私がやっていること - イメージボタンのクリックでユーザーパスワードをリセットします。
これまでに完了 - GridViewCommandEventHandler を追加 - 正しく起動しています。MSDNのコードを使用します。e.CommandArgument の空の文字列 ("") を取得しています。実行時にエラーがスローされます ("" を int に解析できません)。
デバッガーで、「rowIndex」プロパティが e の別の場所に保存されていることを確認できます (私のクリックに対して正しく)。これにアクセスできますか? MSDN のコードは機能すると思います。このエラーを発生させるために他に何かしたことはありますか、またはそれを修正する別の方法はありますか? ありがとう。
void resetpassword(Object sender, GridViewCommandEventArgs e)
{
// If multiple ButtonField columns are used, use the
// CommandName property to determine which button was clicked.
if (e.CommandName == "resetpass")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection. Use the
// CommandSource property to access the GridView control.
GridView GridView1 = (GridView)e.CommandSource;
GridViewRow row = GridView1.Rows[index];
String usrname = row.FindControl("username").ToString();
aspx ページ コード:
<asp:TemplateField HeaderText="Reset Password">
<ItemTemplate>
<asp:ImageButton ID="ibtnReset" runat="server" CausesValidation="false"
CommandName="resetpass" ImageUrl="~/Images/glyphicons_044_keys.png" Text="Button" />
</ItemTemplate>
<HeaderStyle Width="70px" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
イベント追加コード:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
GridView1.RowCommand += new GridViewCommandEventHandler(this.resetpassword);
}