在我的網格視圖中,我希望當用戶點擊激活時,它會導航到activate.aspx頁面。我想從前一頁檢索三個值到activate.aspx頁面。我的代碼是:輸入字符串格式不正確以檢索gridview值
protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.PreviousPage != null)
{
int rowIndex = int.Parse(Request.QueryString["RowIndex"]);
GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
GridViewRow row = GridView1.Rows[rowIndex];
Label1.Text = row.Cells[3].Text;
Label2.Text = row.Cells[2].Text;
Label3.Text = row.Cells[2].Text;
SqlDataAdapter da = new SqlDataAdapter("insert into login values('" + Label1.Text + "','" + Label2.Text + "','" + Label3.Text + "')",con);
DataSet ds = new DataSet();
da.Fill(ds);
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Redirect")
{
String email = "lblemail.Text";
String mob = "lblmobno.Text";
Server.Transfer("activate.aspx?RowIndex=" + email +mob, true);
}
}
ASPX標記
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="Larger" HeaderText="Activate/Delete"
ItemStyle-Width="150px">
<ItemTemplate>
<asp:LinkButton ID="linkbutton1" runat="server" Text="Activate" CommandName="Redirect"
CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'></asp:LinkButton>
<span onclick="return confirm('Are You sure want to Delete?')">
<asp:LinkButton ID="linkbutton2" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我收到錯誤輸入的字符串格式不正確以下行:
int rowIndex = int.Parse(Request.QueryString["RowIndex"]);
請幫助我。
你爲什麼要通過電子郵件和暴民如rowIndex位置?除了電子郵件和暴民,你想傳遞給activate.aspx的三個值是什麼? – tariq
什麼是'Request.QueryString [「RowIndex」]'int rowIndex = int.Parse(Request.QueryString [「RowIndex」]);' – Grundy
'Request.QueryString [「RowIndex」]中的值是什麼' ? – Rohit