私がやっていること - 画像ボタンクリックでユーザーパスワードをリセットします。ASP GridViewボタンのクリックで行の値を取得
これまでに完了したGridViewCommandEventHandlerが正常終了しました。 MSDNのコードを使用しています。私はe.CommandArgumentの空の文字列( "")を取得していますが、実行中にエラーをスローしています( ""をintに解析できません)。
私はデバッガに 'rowIndex'プロパティが格納されていることがわかります。私は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);
}
ButtonField/ImageButtonのノートに感謝します。なぜ、その部分がうまくいかないのか分かりました。最初のオプションを使い、それは完全に動作しています。 – Volvox