克隆图像按钮后如何选择数据并在网格中显示.. [英] how to select select data and display in grid after cliking on image button..
问题描述
protected void ImageButton2_Click(object sender,ImageClickEventArgs e)
{
ImageButton b =(ImageButton)sender;
GridViewRow row =( GridViewRow)b.Parent.Parent;
int rowIndex = row.RowIndex;
TextBox txtparametername =(TextBox)grdparameter.Rows [1] .Cells [1] .FindControl (txttargetvalue);
MySqlConnection StrConnection = new MySqlConnection();
StrConnection.ConnectionString = StrConn;
try
{
StrConnection.Open();
MySqlCommand StrCommand = new MySqlCommand();
StrCommand.CommandType = CommandType.StoredProcedure;
StrCommand.CommandText =Get_ParameterName;
StrCommand.Connection = StrConnection;
StrCommand.Parameters。加WithValue(_ Tenant_Id,Convert.ToInt32(Session [Tenantid]));
StrCommand.Parameters.AddWithValue(_ Branch_Id,Convert.ToInt32(Session [Branchid]));
StrCommand.Parameters.AddWithValue(_ Patient_Id,Convert.ToInt32(Session [DiagnosisClickId]));
StrCommand.Parameters.AddWithValue(_ DiseaseId,ddlselectdisease .SelectedValue);
MySqlDataReader rdr = StrCommand.ExecuteReader();
while(rdr.Read ())
{
txtparametername.Text = Convert.ToString(rdr [ParameterName]);
}
}
catch(Exception ex)
{
obj.InfoEntry(DateTime.Now ++getpatientdignosisdetails++Docto rDashboard.aspx++ ex.Message,);
obj.InfoEntry(DateTime.Now ++ ex.StackTrace,);
Session [strerrormsg] = DateTime.Now ++getpatientdignosisdetails++DoctorDashboard.aspx++ ex.Message;
Session [strerrortrace] = DateTime.Now ++ ex.StackTrace;
Response.Redirect(ErrorPage.aspx);
}
finally
{
StrConnection.Close();
StrConnection.Dispose();
}
ModalPopup_Items.Show();
ModalPopupExtender1.Show();
Biomade.Visible = true;
LoadDdlDiseaseName();
}
这是例外ption发生
无法将System.Web.UI.Control类型的对象强制转换为''System.Web.UI.WebControls.GridViewRow''。
为什么你使用ImageButton_Click事件如果提供了网格视图的RowCommand事件
使用行命令事件
protected void grvTest_RowCommand( object sender,GridViewCommandEventArgs e)
{
GridViewRow row =(GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
}
这里你将获得完整的行,现在只需找到此行中的控件
像TextBox txt = row.FindControl(YourTextBoxId);
试试这样..如果解决方案使用完全,请接受溶液
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
ImageButton b = (ImageButton)sender;
GridViewRow row = (GridViewRow)b.Parent.Parent;
int rowIndex = row.RowIndex;
TextBox txtparametername = (TextBox)grdparameter.Rows[1].Cells[1].FindControl("txttargetvalue");
MySqlConnection StrConnection = new MySqlConnection();
StrConnection.ConnectionString = StrConn;
try
{
StrConnection.Open();
MySqlCommand StrCommand = new MySqlCommand();
StrCommand.CommandType = CommandType.StoredProcedure;
StrCommand.CommandText = "Get_ParameterName";
StrCommand.Connection = StrConnection;
StrCommand.Parameters.AddWithValue("_Tenant_Id", Convert.ToInt32(Session["Tenantid"]));
StrCommand.Parameters.AddWithValue("_Branch_Id", Convert.ToInt32(Session["Branchid"]));
StrCommand.Parameters.AddWithValue("_Patient_Id", Convert.ToInt32(Session["DiagnosisClickId"]));
StrCommand.Parameters.AddWithValue("_DiseaseId", ddlselectdisease.SelectedValue);
MySqlDataReader rdr = StrCommand.ExecuteReader();
while (rdr.Read())
{
txtparametername.Text = Convert.ToString(rdr["ParameterName"]);
}
}
catch (Exception ex)
{
obj.InfoEntry(DateTime.Now + " " + "getpatientdignosisdetails" + " " + "DoctorDashboard.aspx" + " " + ex.Message, "");
obj.InfoEntry(DateTime.Now + " " + ex.StackTrace, "");
Session["strerrormsg"] = DateTime.Now + " " + "getpatientdignosisdetails" + " " + "DoctorDashboard.aspx" + " " + ex.Message;
Session["strerrortrace"] = DateTime.Now + " " + ex.StackTrace;
Response.Redirect("ErrorPage.aspx");
}
finally
{
StrConnection.Close();
StrConnection.Dispose();
}
ModalPopup_Items.Show();
ModalPopupExtender1.Show();
Biomade.Visible = true;
LoadDdlDiseaseName();
}
this is the exception occurring
Unable to cast object of type ''System.Web.UI.Control'' to type ''System.Web.UI.WebControls.GridViewRow''.
Why you are using ImageButton_Click Event if there is provision of RowCommand Event of grid veiw
Use Row Command Event
protected void grvTest_RowCommand(object sender, GridViewCommandEventArgs e) { GridViewRow row = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer; }
Here you will get full row, now just find the control in this row
like TextBox txt = row.FindControl("YourTextBoxId");
Try like this.. if the solution is use full to you please accept the solution
这篇关于克隆图像按钮后如何选择数据并在网格中显示..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!