2013-10-08 4 views
0

다음과 같이 한 페이지에 gridview가 있습니다. Gridview에서 다른 페이지로 값 가져 오기

<asp:GridView ID="gvDoctorList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
          AllowPaging="True" AllowSorting="True" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"> 
          <Columns> 
           <asp:TemplateField> 
            <ItemTemplate> 
             <asp:CheckBox runat="server" ID="chk" OnCheckedChanged="chk_CheckedChanged" /> 
             <asp:Label runat="server" ID="lblPID" Visible="false" Text='<%# Eval("PatientId") %>'></asp:Label> 
            </ItemTemplate> 

           </asp:TemplateField> 

           <asp:BoundField DataField="PatientId" HeaderText="PatientId" SortExpression="PatientId" /> 
           <asp:BoundField DataField="firstname" HeaderText="firstname" SortExpression="firstname" /> 
           <asp:BoundField DataField="lastname" HeaderText="lastname" SortExpression="lastname" /> 

           <asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" /> 

          </Columns> 
         </asp:GridView> 
         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDatabaseConnectionString %>" 
          SelectCommand="SELECT [PatientId],[firstname], [lastname], [sex] FROM [PatientDetails]"></asp:SqlDataSource> 

지금 사용자 확인이 체크 박스 같은 시간에 나는 다른 페이지에있는 gridview에서 PatientId을 할 때 더욱 나는 SQL 테이블에 PatientId을 삽입 할. 어떤 사람이 나에게 코드 업데이트]

* :: *을 주면

많이 감사

내를 Page_Load 코드는

if (!IsPostBack) { 
foreach (GridViewRow row in gvDoctorList.Rows) 
{ 
    CheckBox chk = (CheckBox)row.FindControl("chk"); 
    if (chk.Checked) 
    { 
    string patientId = ((Label)row.FindControl("lblPID")).Text; 
    string exam = ((Button)sender).Text; 
    Session[patientId] = patientId; 
    } 
    } 
} 
+2

부모 변수를 세션 변수에 넣고 다른 페이지로 이동하는 동안/다른 방법으로 쿼리 문자열로 전달할 수 있습니다. – Rex

+0

pageload에서 세션을 넣을 위치는 어디입니까? – Pratik

+0

당신이 사용할 수있는 세션을 사용하여 귀하의 용도에 따라 – Rex

답변

1

왜이 기능을 사용하지 않으시겠습니까 ?? 이 PatientID의 값에 의해

Session ["PatientID"] = YoureGridView.SelectedRow.Cells[indexOfPatientID].Text; 

세션에서 당신이

Int PatientID = Convert.Toint16(Session["PatientID"]); 

를 사용하여 세션에서 데이터를 검색 할 수있는 다른 페이지로 이동하는 경우 또는 그 경우 문자열되어

string PatientID = Session["PatientID"].ToString(); 

음 나는 당신이 충분한 정보를 제공하지 못했기 때문에 추측하고 있습니다.하지만 그것은 다른 웹 페이지로 데이터를 전송하려고한다면 어떻게 코드합니까?

그 TSQL을 SQL에 삽입하고 가정을위한

은 내가 좀 더 확실한 대답의 시도 게시 이상 우리에게 이야기를하려는 경우 그럼이 다시 단지 예이다이

 SqlCommand Update = new SqlCommand(); 
     Update.Connection = YourConnection; 
     Update.CommandType = CommandType.StoredProcedure; 
     Update.CommandText = "usp_YoureStoredProcedure"; 
     Update.Parameters.AddWithValue("@id", Convert.Toint16(Session["PatientID"])); //the convert varies on what data type you are using this is just an example 

같은 것을 사용합니다.

+0

하지만 내가 세션 [ "PatientID"] = YoureGridView.SelectedRow.Cells [indexOfPatientID]. 텍스트; – Pratik

+0

.Cells [indexOfPatientID] .Text ...를 얻을 수 없습니다. 그래서 문제가 될 수 있으니 알려주십시오. – Pratik

+0

-_- 물론 그것이 작동하지 않는다면 [1], [2] – user2705620

관련 문제