sudharsan s

sudharsan s

  • NA
  • 204
  • 85.2k

how to pass grid row field values to another page text fields after clicking link buton?

Aug 7 2012 2:55 AM
hi.

after cliicking linkbutton (Select)which is grid:

I got invalid column name error(HospitalNo) getting,, try solve this problem.



grid page behind code:

RegisteredPatient.aspx.cs

protected void gvNewRegistration_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string sid = gvNewRegistration.DataKeys[e.Row.RowIndex]["HospitalNo"].ToString();
            LinkButton lnkDetailss = (LinkButton)e.Row.Cells[0].Controls[1];

           
            if (lnkDetailss.Text == "Select")
            {
                lnkDetailss.PostBackUrl = "NewIP_Register.aspx?res=0&sid=" + sid.ToString() + "&Action=select";
            }

}
           
      }


2 nd page :

NewIp_Register.aspx.cs



using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

public partial class NewIP_Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string action = Request.QueryString["Action"].ToString();
            if (action == "select")
            {

                string ids = Request.QueryString["sid"].ToString();
              
                string dbConn = ConfigurationManager.ConnectionStrings["CMC"].ConnectionString;
                SqlConnection sqlConn = new SqlConnection(dbConn);
                sqlConn.Open();
                SqlCommand cmd = new SqlCommand("SELECT [Title],[Patient_Name],[Street],[City],[State],[Country],[Zip_Code],[Phone_1],[Phone_2],[Mobile_Number],[Ward],[MR_Number],[HospitalNo],[Patient_Type],[Sex],[Date_Admitted],[tinYear],[tinMonth],[tinDays],[BillType],[RefBy],[CorporateCode],[PackageCode],[InsuranceCode] FROM [registration_details] where HospitalNo=" + ids,sqlConn);
                //string query = " select c.*,s.status as s1,p.priority as p1,d.dept as d1,e.ename as sname from complaint c,status s,priority p,dept d,empdetails e where e.mobilenumber=c.callerinfo and p.id=c.priority and d.id=c.complaintcategory and s.status=c.status  order by complaintid desc";
                //MySqlCommand cmd = new MySqlCommand(query, m);
              
                SqlDataReader dr = cmd.ExecuteReader();
                DataTable dt = new DataTable();
                dt.Load(dr);
                sqlConn.Close();
                DataTable dt1 = new DataTable();
                ddlPatientType.SelectedItem.Text=dt.Rows[0]["Patient_Type"].ToString();
                ddlBillType.SelectedItem.Text=dt.Rows[0]["BillType"].ToString();
                 ddlTitle.SelectedItem.Text=dt.Rows[0]["Title"].ToString();
               txtPatientName.Text = dt.Rows[0]["Patient_Name"].ToString();
               ddlGender.SelectedItem.Text = dt.Rows[0]["Sex"].ToString();
               txtHospitalNo.Text = dt.Rows[0]["HospitalNo"].ToString();
               txtStreet.Text = dt.Rows[0]["Street"].ToString();
               txtYears.Text = dt.Rows[0]["tinYear"].ToString();
               txtMonth.Text = dt.Rows[0]["tinMonth"].ToString();
               txtDays.Text = dt.Rows[0]["tinDays"].ToString();
               txtDateAdmitted.Text = dt.Rows[0]["Date_Admitted"].ToString();
               txtPinCode.Text = dt.Rows[0]["Zip_Code"].ToString();
               txtPhone1.Text = dt.Rows[0]["Phone_1"].ToString();
               txtPhone2.Text = dt.Rows[0]["Phone_2"].ToString();
               txtCity.Text = dt.Rows[0]["City"].ToString();
               txtMobileNo.Text = dt.Rows[0]["Mobile_Number"].ToString();
               ddlState.SelectedItem.Text = dt.Rows[0]["State"].ToString();
               ddlWard.SelectedItem.Text = dt.Rows[0]["Ward"].ToString();
               ddlWard.Text = dt.Rows[0]["Mobile_Number"].ToString();
               txtCountry.Text = dt.Rows[0]["Country"].ToString();
               ddlCorporate.SelectedItem.Text = dt.Rows[0]["CorporateCode"].ToString();
               ddlPackage.SelectedItem.Text = dt.Rows[0]["PackageCode"].ToString();
               ddlInsurance.SelectedItem.Text = dt.Rows[0]["InsuranceCode"].ToString();
             
            }
        }
    }
}