China Naming Network - Company naming - How to set the properties of a user control after a page postback.

How to set the properties of a user control after a page postback.

Extract the code in Page_Load from the database and put it in an independent method, such as named getdata ();

public void GetData()

{

_GetSelectValue = ClassListID。 The selected value;

ClassListID。 items . Clear();

String Sql

if (Cache["ClassID"]! = null & amp& amp cache ["classic"]. ToString()! = "")

{

SQL = " SELECT * FROM project class WHERE project class。 ParentPath similar to "%"+cache ["classid"]. ToString()+",%' or ParentID ="+Cache["ClassID"]. ToString() + " ORDER BY RootID,OrderID ";

}

other

{

SQL = " SELECT * FROM project class ORDER BY RootID,OrderID ";

}

SqlDataReader dr = SqlHelper。 ExecuteReader(SqlHelper。 ConnectionString,CommandTypeText,Sql);

If (! _ enabled)

{

ClassListID。 Attributes.Add("disabled "," disabled ");

}

if (_IsList)

{

ClassListID。 Attributes.Add("size "," 20 ");

ClassListID。 Style.Add(HtmlTextWriterStyle。 Width, "280 pixels");

}

if (_ShowFirst)

{

ClassListID。 items . Add(new ListItem(_ first text,“0”);

}

while (dr.Read())

{

String Nbsp = null// variables with spaces;

string optionText = null

If (conversion. toint 16(dr[" ParentID "])= = 0)

{

optionText = HttpUtility。 html decode(" "+dr[" class name "];

}

other

{

int STM_Path = Convert。 ToInt 16(dr[ "depth"]); //If the ParentID is not 0, it means it is not the root element, and find out which layer it is;

for(int I = 0; I & ltSTM _ Pathi++)

{

//Add 4 spaces on each floor;

Nbsp += HttpUtility。 html decode(" ");

}

option text = nbsp+"├"+dr[" class name "];

}

ClassListID。 Items.Add (new ListItem(optionText, dr["ClassID"]). ToString()));

}

Dr. Close ();

dr . Dispose();

}

Protected void Page_Load (object sender, EventArgs e)

{

If (! IsPostBack)

{

get data();

ClassListID。 SelectedValue = _ SetSelectValue

}

}

Then in the button event of the page:

Protected void Button 1_Click (object sender, EventArgs e)

{

ClassID。 IsList = true

ClassID。 get data();

}