Hi, i can able to generate dynamic pages using basepage.cs,template.tmp,and like master page (createpage.ascx,headerpage.ascx,footerpage.ascx).while generating page it is dynamically generation page name like 1122348803-investment.aspx. now what i want is, i need a drop down list that must contain the dynamic pages names. should to redirect to that page once we selected that option.
to generate the dynamic pages i used this code in middle u can see the value inserting into the database.. i'm saving auto generating file name and name which is present in the drop down list into the database
protected void btnGenerate_Click(object sender, EventArgs e)
{
String root = Server.MapPath("~");
String pgTemplate = root + "\\myPageTemplate.tmp";
StringBuilder line = new StringBuilder();
using (StreamReader rwOpenTemplate = new StreamReader(pgTemplate))
{
while (!rwOpenTemplate.EndOfStream)
{
line.Append(rwOpenTemplate.ReadToEnd());
}
}
int ID = 0;
string SaveFilePath = "";
string SaveFileName = "";
string filename = "";
Random ran = new Random();
ID = ran.Next();
Title = ID.ToString() + "" + txtTitle.Text.Replace(' ', '-').Replace('.', '-').Replace('#', '-').Replace('%', '-').Replace('&', '-').Replace('*', '-').Replace('@', '-').Replace('!', '-').Replace('|', '-').Replace(':', '-').Replace(';', '-').Replace(',', '-').Replace('/', '-').Replace('\\', '-').Replace('?', '-').Replace('<', '-').Replace('>', '-').Replace('"', '-').Replace('"', '-').Replace('"', '-');
SaveFileName = "\\" + Title + ".aspx";
filename = Title + ".aspx"; ;
SaveFilePath = root + "\\myPages\\" + SaveFileName;
FileStream fsSave = File.Create(SaveFilePath);
string ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(ConnectionString))
{
SqlCommand cmd = new SqlCommand("spinsertvalue", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@value", filename);
cmd.Parameters.AddWithValue("@optionname", txtTitle.Text);
con.Open();
cmd.ExecuteNonQuery();
}
if (line != null)
{
line.Replace("[MetaTitle]", txtTitle.Text.Replace("<", "<").Replace(">", ">").Replace('"', ' ').Replace('"', ' '));
line.Replace("[ID]", ID.ToString());
StreamWriter sw = null;
try
{
sw = new StreamWriter(fsSave);
sw.Write(line);
lnkNewPage.Text = SaveFilePath;
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
}
finally
{
sw.Close();
}
}
}
<asp:DropDownList ID="DropDownList1" DataTextField="value"
DataValueField="optionname" runat="server"
AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
here i'm trying to fetch the data from database to redirect to the page when we select the option in the drop down list.. but the problem is it is not taking option name in the drop down list in string dropvalue = DropDownList1.DataValueField; always showing null
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string dropvalue = DropDownList1.DataValueField;
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spGetDropdownValue", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@optionname", DropDownList1.SelectedItem.Text);
con.Open();
string TotalRows = (string)cmd.ExecuteScalar();
Response.Write("Total Rows = " + TotalRows.ToString());
string path = "~/myPages/" + TotalRows.ToString();
Response.Redirect(path);
}
}