M
Mike P
I have the following code in my Page_Load event to populate a listbox
from a database :
if (!(Page.IsPostBack))
{
SqlConnection objConnection = new
SqlConnection(ConfigurationSettings.AppSettings["strConnectTransitTest"]
);
string strTelcoNumber = "SELECT DISTINCT OSValue FROM CallTypeSwitch
ORDER BY OSValue";
//You must open the connection before populating the DataReader
objConnection.Open();
SqlCommand objCmd = new SqlCommand(strTelcoNumber, objConnection);
//Create/Populate the DataReader
SqlDataReader objDataReader = null;
objDataReader = objCmd.ExecuteReader();
//Databind the DataReader to the listbox Web control
lstRoutes.DataSource = objDataReader;
lstRoutes.DataBind();
}
What I want to do is to get rid of the IsPostback so that if the
database is updated the listbox will also be updated. But in order to
do this I need to store the value chosen by the user and set the listbox
to that value on my Submit button click event. I think ViewState might
be the right way to go about this but I have no real experience of using
this in C#. Does any body know how to do this?
Any advice would be much appreciated.
Cheers,
Mike
from a database :
if (!(Page.IsPostBack))
{
SqlConnection objConnection = new
SqlConnection(ConfigurationSettings.AppSettings["strConnectTransitTest"]
);
string strTelcoNumber = "SELECT DISTINCT OSValue FROM CallTypeSwitch
ORDER BY OSValue";
//You must open the connection before populating the DataReader
objConnection.Open();
SqlCommand objCmd = new SqlCommand(strTelcoNumber, objConnection);
//Create/Populate the DataReader
SqlDataReader objDataReader = null;
objDataReader = objCmd.ExecuteReader();
//Databind the DataReader to the listbox Web control
lstRoutes.DataSource = objDataReader;
lstRoutes.DataBind();
}
What I want to do is to get rid of the IsPostback so that if the
database is updated the listbox will also be updated. But in order to
do this I need to store the value chosen by the user and set the listbox
to that value on my Submit button click event. I think ViewState might
be the right way to go about this but I have no real experience of using
this in C#. Does any body know how to do this?
Any advice would be much appreciated.
Cheers,
Mike