how can i make this code more optimized
Easy enough. You're only ever making one item visible depending on the case option, so just set the visibility as follows:
pnlDate.Visible = (selVal == "date"); pnlSubject.Visible = (selVal == "subject");pnlofficer.Visible = (selVal == "officer");pnlCIA.Visible = false;pnlMedia.Visible = false;pnlStatus.Visible = (selVal == "status");
This is better than setting everything to visible = false;
and then only showing the item you need as this contains it all into just 6 lines of code for the actual visibility setting.
protected void ddlFilterResultBy_SelectedIndexChanged(object sender, EventArgs e) { string selVal = ddlFilterResultBy.SelectedValue.ToString().ToLower(); pnlDate.Visible = false; pnlSubject.Visible = false; pnlofficer.Visible = false; pnlCIA.Visible = false; pnlMedia.Visible = false; pnlStatus.Visible = false; switch (selVal) { case "date": pnlDate.Visible = true; break; case "subject": pnlSubject.Visible = true; break; case "officer": pnlofficer.Visible = true; break; case "status": pnlStatus.Visible = true; break; } }