I have two table
Table 1: job_details
Job_id
Project Name
Table 2: chap_details
chap_id
Job_id
chap_no
ms_pages
In the aspx page, I have grid view and details view.
My problem is
In the gridview, template fields called job_id, chapter_no
and view button
whenever i select the chapter of particular job and click the view button.
It displays the ms pages of the particular job and chapter.
Note: A job can have multiple chapters
But in the following program works when i select the first value value in the dropdown chapter list box.
Plz help me.
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" EnableEventValidation="false" %>
C#:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
public partial class Default2 : System.Web.UI.Page
{
SqlConnection sqlCon = new SqlConnection();
SqlCommand sqlCmd = new SqlCommand();
string connectionString;
protected void Page_Load(object sender, EventArgs e)
{
OpenConnection();
if (!IsPostBack)
{
fnFillGrid();
fillDdlChapter();
secondDiv.Visible = false;
}
}
public void OpenConnection()
{
connectionString = System.Configuration.ConfigurationSettings.AppSettings["myconn"];
sqlCon = new SqlConnection(connectionString);
sqlCon.Open();
}
public void fnFillGrid()
{
DataSet ds = new DataSet();
sqlCmd = new SqlCommand("select distinct(job_id) from job_details order by job_id", sqlCon);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlCmd;
da.Fill(ds);
grvTask.DataSource = ds;
grvTask.DataBind();
}
public void fillDdlChapter()
{
for (int i = 0; i < grvTask.Rows.Count; i++)
{
Label lblJob_no = ((Label)(grvTask.Rows[i].Cells[2].Controls[1]).FindControl("lblJob_no"));
DropDownList ddlchapter = ((DropDownList)(grvTask.Rows[i].Cells[2].Controls[1]).FindControl("ddChapter"));
DataSet ds = new DataSet();
sqlCmd = new SqlCommand("select distinct(chapter_no),job_id from chap_details where job_id ='" + lblJob_no.Text + "' ", sqlCon);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlCmd;
da.Fill(ds);
ddlchapter.DataSource = ds;
ddlchapter.DataValueField = "job_id";
ddlchapter.DataTextField = "chapter_no";
ddlchapter.DataBind();
}
}
protected void btnView_Click(object sender, EventArgs e)
{
string jobno = Convert.ToString(((HiddenField)(((Button)sender).Parent.FindControl("hdnJobNo"))).Value);
string chapter = Convert.ToString(((DropDownList)(((Button)sender).Parent.FindControl("ddChapter"))).SelectedItem);
secondDiv.Visible = true;
DataSet ds = new DataSet();
sqlCmd = new SqlCommand("select job_id,chapter_no,ms_pages from chap_details where job_id='" + jobno + "' and chapter_no='" + chapter + "'", sqlCon);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlCmd;
da.Fill(ds);
grvDetails.DataSource = ds;
grvDetails.DataBind();
}
}
Problem is: when i am selecting the second item in the dropdown box of a particular job means it shoes the first item value in the details view.
bye
Murugavel S
Suthish NairPosted Dec 16, 2010, 11:59 AM
refer link
Also, revisit your logic. Why you opening a DB connection on Page Load.
Try like this..., put a breakpoint and check each line.
Murugavel SadagopanPosted Dec 16, 2010, 10:40 AM
No.
My problem is whenever i select the any value in the dropdownbox from the gridview. It shows only the first value details in the detailview.
Thanks
Murugavel S
Suthish NairPosted Dec 16, 2010, 5:30 AM
Your query resolved?
Or please explain what actual probs you facing.
Murugavel SadagopanPosted Dec 15, 2010, 12:12 PM
Attached document is for your reference
bye
Murugavel S