TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ToBe
NA
164
94.4k
populate my controls in the Page load
May 7 2013 8:35 AM
hi
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;
}
}
}
}
}
Reply
Answers (
8
)
Ethernet Port C#
Import/Export Generic List Objects