2012-01-01 2 views
1

데이터리스트에 표시되는 각 게시물의 등급 척도로 RadioButtonList가 포함 된 데이터리스트를 작성하고 있습니다. 그러나 한 게시물을 평가할 때 다른 모든 게시물의 등급이 같을 때 문제가있는 곳을 말해 줄 수 있습니까? , 감사. PS : 나는 문제가 내가 그것을 제거한 경우, 내가 DataListItem를 얻기 위해 RadioButtonList 또는 postIDLabel데이터리스트 내부의 컨트롤에 액세스

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { 
    foreach (DataListItem item in DataList2.Items) { 
    RadioButtonList RadioButtonList1=(RadioButtonList)item.FindControl("RadioButtonList1"); 
    string choice = RadioButtonList1.SelectedValue; 

    Label post_IDLabel = (Label)item.FindControl("post_IDLabel"); 
    int post_ID = Convert.ToInt32(post_IDLabel.Text); 
    int value = Convert.ToInt32(choice); 

    string connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString(); 
    SqlConnection conn = new SqlConnection(connStr); 

    SqlCommand cmd = new SqlCommand("rate", conn); 
    cmd.CommandType = CommandType.StoredProcedure; 
    string email = Session["email"].ToString(); 
    int course_ID = Convert.ToInt32(Request.QueryString["courseID"]); 
    cmd.Parameters.Add(new SqlParameter("@course_ID", course_ID)); 
    cmd.Parameters.Add(new SqlParameter("@postID", post_ID)); 
    cmd.Parameters.Add(new SqlParameter("@myemail", email)); 
    cmd.Parameters.Add(new SqlParameter("@rate", value)); 

    conn.Open(); 
    cmd.ExecuteNonQuery(); 
    conn.Close(); 

    Response.Write(choice); 
    } 
    DataList2.DataBind(); 
} 
+0

일부 ASPX 코드를 볼 수 있습니까? – dotnetstep

답변

2

사용 NamingContainer에 액세스 할 수 없습니다 누구든지 foreach 루프에 있음을 알고있다.

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
RadioButtonList rad = sender as RadioButtonList; 
DataListItem item = rad.NamingContainer as DataListItem; 
Label lab = item.FindControl("postIDLabel") as Label ; 
Response.Write(lab.Text); 
} 
관련 문제