如何将所选行的ID传递到下一页
问题描述:
大家好
这是我的代码,我要将所选行的IMAGE_ID传递到下一页..plzhelp
Hi all
here is my code where i want to pass the IMAGE_ID of selected rows onto next page..plz help
public partial class ADMIN_SELECT_IMAGE : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindGridView();
}
private void BindGridView()
{
ConnectionStringSettings set = ConfigurationManager.ConnectionStrings["WATERMARKING"];
String cns = set.ConnectionString;
SqlConnection con = new SqlConnection(cns);
con.Open();
string sql = "Select IMAGE_ID,IMAGE_TYPE,IMAGE_SIZE,IMAGE_CONTENT from IMAGE";
SqlDataAdapter da = new SqlDataAdapter(sql, cns);
DataTable dt = new DataTable();
da.Fill(dt);
gvCheckboxes.DataSource = dt;
gvCheckboxes.DataBind();
con.Close();
}
protected void gvCheckboxes_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void SelectRecords(StringCollection sc)
{
//int id =(int)this.gvCheckboxes.SelectedDataKey.Value;
ConnectionStringSettings set = ConfigurationManager.ConnectionStrings["WATERMARKING"];
String cns = set.ConnectionString;
SqlConnection con = new SqlConnection(cns);
con.Open();
StringBuilder sb = new StringBuilder(string.Empty);
foreach (string item in sc)
{
const string sqlStatement = "SELECT IMAGE_ID,IMAGE_CONTENT FROM IMAGE WHERE IMAGE_ID";
sb.AppendFormat("{0}='{1}'; ", sqlStatement, item);
}
try
{
SqlCommand cmd = new SqlCommand(sb.ToString(), con);
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
reader.Read();
if (reader.HasRows)
{
Response.Redirect("ADMIN_SELECT_LOGO.aspx");
}
else
{
//Response.Write("image deleted successfully");
Response.Write("error in selection");
}
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
con.Close();
}
}
protected void ButtonSelect_Click(object sender, EventArgs e)
{
StringCollection sc = new StringCollection();
string id = string.Empty;
for (int i = 0; i < gvCheckboxes.Rows.Count; i++)
{
CheckBox cb = (CheckBox)gvCheckboxes.Rows[i].Cells[0].FindControl("CheckBox1");
if (cb != null)
{
if (cb.Checked)
{
id = gvCheckboxes.Rows[i].Cells[1].Text;
sc.Add(id);
}
}
}
SelectRecords(sc);
BindGridView();
}
protected void gvCheckBoxes_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
Button b = (Button)e.Row.FindControl("ButtonSelect");
b.Attributes.Add("onclick", "return ConfirmOnSelect();");
}
}
protected void LinkButton7_Click1(object sender, EventArgs e)
{
Response.Redirect("ADMIN_HOME.aspx");
}
protected void LinkButton6_Click1(object sender, EventArgs e)
{
Response.Redirect("LOGIN.aspx");
}
}
答
好吧,您说您正在尝试通过会话,但是代码并未反映出这一点.
此示例 [
well, you say you are trying to pass thru sessions, but the code does not reflect this.
this example[^] shows how to use sessions with a good bunch of information:
(an example code from the link)
//Storing UserName in Session
Session["UserName"] = txtUser.Text;
//Check weather session variable null or not
if (Session["UserName"] != null)
{
//Retrieving UserName from Session
lblWelcome.Text = "Welcome : " + Session["UserName"];
}
else
{
//Do Something else
}
此外,对象可以存储在会话中:
in addition, objects can be stored in sessions:
//Storing dataset on Session
Session["DataSet"] = _objDataSet;
//and following code shows how we can retrieve that dataset from the session
//Check weather session variable null or not
if (Session["DataSet"] != null)
{
//Retrieving UserName from Session
DataSet _MyDs = (DataSet)Session["DataSet"];
}
else
{
//Do Something else
}
相反,您可以在此处 [
instead, you can use query strings as in here[^]
带有会话变量或querystring参数.
With either a session variable or a querystring parameter.