B
ben
Hi All,
I have a Listbox which gets populated from the database.On selecting
an item in the list, i would like to populate some other
fields......it was working fine until i added
autopostback="true"...now it gives me an error saying"Object does not
support this method or property( IE Script error)
If i remove the AutoPostBack="true", then the error does not
appear....
Code SNippets Follow:
string selecttext="select cUserID,(cFirstname+' '+cLastName) fullName
from tblUser ;
DataTable dataTable = new DataTable();
SqlDataAdapter mydataAdapter=new SqlDataAdapter();
mydataAdapter.SelectCommand=mycommand;
mydataAdapter.Fill(dataTable);
lb1.DataSource=dataTable;
lb1.DataTextField="fullName";
lb1.DataValueField="cUserID";
lb1.DataBind();
public void lb1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
string connstr=ConfigurationSettings.AppSettings["ConnectionString"];
string selecttext="select Firstname,LastName from tblUser where
cUserID="+lb1.SelectedItem.Value;
SqlConnection con=new SqlConnection(connstr);
SqlCommand mycommand=new SqlCommand(selecttext,con);
con.Open();
SqlDataReader dr= mycommand.ExecuteReader();
while(dr.Read())
{
txtfname.Text=dr["FirstName"].ToString();
txtlname.Text=dr["LastName"].ToString();
}
}
<asp:listbox id="lb1" runat="server" Height="216px" Width="178px"
SelectionMode="Single"
AutoPostBack="True" OnSelectedIndexChanged="lb1_SelectedIndexChanged"></asp:listbox>
ANy help is appreciated,
Thanks,
Ben
I have a Listbox which gets populated from the database.On selecting
an item in the list, i would like to populate some other
fields......it was working fine until i added
autopostback="true"...now it gives me an error saying"Object does not
support this method or property( IE Script error)
If i remove the AutoPostBack="true", then the error does not
appear....
Code SNippets Follow:
string selecttext="select cUserID,(cFirstname+' '+cLastName) fullName
from tblUser ;
DataTable dataTable = new DataTable();
SqlDataAdapter mydataAdapter=new SqlDataAdapter();
mydataAdapter.SelectCommand=mycommand;
mydataAdapter.Fill(dataTable);
lb1.DataSource=dataTable;
lb1.DataTextField="fullName";
lb1.DataValueField="cUserID";
lb1.DataBind();
public void lb1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
string connstr=ConfigurationSettings.AppSettings["ConnectionString"];
string selecttext="select Firstname,LastName from tblUser where
cUserID="+lb1.SelectedItem.Value;
SqlConnection con=new SqlConnection(connstr);
SqlCommand mycommand=new SqlCommand(selecttext,con);
con.Open();
SqlDataReader dr= mycommand.ExecuteReader();
while(dr.Read())
{
txtfname.Text=dr["FirstName"].ToString();
txtlname.Text=dr["LastName"].ToString();
}
}
<asp:listbox id="lb1" runat="server" Height="216px" Width="178px"
SelectionMode="Single"
AutoPostBack="True" OnSelectedIndexChanged="lb1_SelectedIndexChanged"></asp:listbox>
ANy help is appreciated,
Thanks,
Ben