I have one button rertive the data based on the REG_NO passed by the previous form and fill it in the form controls .
i want to show it directly and populate and fill my controls with data in the page load without clicking the button
this is my current code :
public partial class EditFrm : System.Web.UI.Page
{
string myconn = ConfigurationManager.ConnectionStrings["REGConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
LabelReg.Text =Request.QueryString["REG_NO"].ToString();
}
protected void View_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(myconn);
string rf = Session["REG_NO"].ToString();
string sqlstr = "SELECT REG_NO,CITY,SUbmit_date,Address,Type,Age,ID FROM tblMain INNER JOIN tblCity ON tblMain.City_ID =tblCity.City_ID INNER JOIN tblType ON tblMain.Current_ID =tblType.Type_ID WHERE REG_NO ='" + LabelReg.Text + "'";
con.Open();
SqlCommand cmd = new SqlCommand(sqlstr, con);
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 15;
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet DS = new System.Data.DataSet(cmd.CommandText);
ad.Fill(DS);
if (DS.Tables[0].Rows.Count > 0)
{
foreach (ListItem litem in rdblCity.Items)
{
if (litem.Text == DS.Tables[0].Rows[0].ItemArray[1].ToString())
{
litem.Selected = true;
}
}
foreach (ListItem litem1 in rdblAge.Items)
{
if (litem1.Text == DS.Tables[0].Rows[0].ItemArray[5].ToString())
{
litem1.Selected = true;
}
}
txtreg_no.Text = DS.Tables[0].Rows[0].ItemArray[0].ToString();
txtSubmit_Date = DS.Tables[0].Rows[0].ItemArray[2].ToString();
txtAddress.Text = DS.Tables[0].Rows[0].ItemArray[3].ToString();
string sqlstr2 = "SELECT Type_ID, Type_Name FROM tblType where Type_ID = " + DS.Tables[0].Rows[0].ItemArray[6].ToString();
SqlCommand cmd2 = new SqlCommand(sqlstr2, con);
cmd2.CommandType = CommandType.Text;
cmd2.CommandTimeout = 15;
SqlDataAdapter ad2 = new SqlDataAdapter(cmd2);
DataSet DS2 = new System.Data.DataSet(cmd2.CommandText);
ad2.Fill(DS2);
if (DS2.Tables[0].Rows.Count > 0)
{
foreach (DataRow temp in DS2.Tables[0].Rows)
{
foreach (ListItem litem6 in chktype.Items)
{
if (litem6.Text == temp.ItemArray[1].ToString())
{
litem6.Selected = true;
}
}
}
}
}
Jay SPosted May 8, 2013, 6:31 AM
Connection con = new Connection("ConnectionString");
DataAdapter da = new DataAdapter("Select FCBL_Draft_Notifications.Email1 from ....",con);
DataSet ds = new DataSet();
da.Fill(ds,"Email");
RadioButtonList.DataTextField = "ColumnName" //For display purpose
RadioButtonList.DataValueField = "ColumnName" //For storing in DB
RadioButtonList.DataSource = ds.Tables["Email"];
RadioButtonList.DataBind();
ToBePosted May 8, 2013, 8:05 AM
Jay SPosted May 8, 2013, 6:57 AM
I'd suggest looking at creating a DAL.
ToBePosted May 8, 2013, 6:51 AM
ToBePosted May 8, 2013, 6:08 AM
Jay SPosted May 8, 2013, 6:06 AM
You should have that information either in a Data Access Layer, or my preference, use Entity Framework.
You should have a clear distinction what each layer is doing.
Have you stepped through your code to see where it's dropping out the population?
ToBePosted May 8, 2013, 5:52 AM
now i don't need to click the view_button :)
but theirs no data in the radiobuttonlist or in the checkboxes when I design my form i used the Visual studio configuration wizard to get my data sources I didn't hard coded it it's in my HTML :
for i.e :
Jay SPosted May 8, 2013, 5:41 AM