在网格视图单元格中创建会话
本文关键字:创建 会话 单元格 网格 视图 | 更新日期: 2023-09-27 18:25:58
我有一个带有tempaltefield按钮的网格视图,我想用选定按钮行中的单元格值创建一个会话,有人能帮我吗?我试过了,但没用:
protected void ImageButton1_Clickk1(对象发件人,ImageClickEventArgs e){Session["mysession"]=GridView1.SelectedRow.Cells[1].Text;}
首先,如果它只是模板字段中的一个image按钮,实际上您不会选择取消行。由于SelectedRow为null,此行可能引发异常。但是,如果您使用命令进行选择,那是正确的。也许您的事件(ImageButton1_Click1)没有分配给您的图像(OnClick)。
你可以试试这样的东西:
protected void Page_Load(object sender, EventArgs e)
{
try
{
//Add and event RowDataBound
grvGrid.RowDataBound += new GridViewRowEventHandler(grvGrid_RowDataBound);
}
catch
{
//...throw
}
}
protected void grvGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.Header)
{
//...
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Add an ImageButton foreach row in GridView
ImageButton ibtImageAlt = new ImageButton();
ibtImageAlt.ImageUrl = "App_Images/y.gif";
//ImageButton's ID will be the index of the row
ibtImageAlt.ID = e.Row.RowIndex.ToString();
ibtImageAlt.ForeColor = System.Drawing.Color.White;
ibtImageAlt.Font.Overline = false;
ibtImageAlt.Click += ibtImageAlt_Click;
}
}
catch
{
//...throw
}
}
protected void ibtImageAlt_Click(object sender, EventArgs e)
{
try
{
//Catch the ImageButton ID and the row in GridView
//An example to catch the value of the row selected by the ImageButton
Int32 intIndexRow = Convert.ToInt32(((ImageButton)sender).ID);
String strTest = grvGrid.Rows[intIndexRow].Cells[0].Text;
}
catch
{
//...throw
}
}