本文介绍了是否有可能从stringbuilder获取当前值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public string GetConnectionStrings()
{
string ConStr = "server=ACDDXB-PC03\\MSSQL2008;uid=sa;pwd=sa12345;database=DocManager";
return ConStr;
}
public DataTable SelectDataTable(String Sql)
{
DataTable dt = new DataTable();
SqlConnection oSqlConnection = new SqlConnection(GetConnectionStrings());
try
{
oSqlConnection.Open();
SqlDataAdapter sqlda = new SqlDataAdapter(Sql, GetConnectionStrings());
sqlda.Fill(dt);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
oSqlConnection.Close();
oSqlConnection.Dispose();
}
return dt;
}
private string GenerateMenu(DataRow[] drParentMenu, DataTable oDataTable, StringBuilder oStringBuilder)
{
string FixedMenuFlg = "";
if (page == 0)
{
oStringBuilder.AppendLine("<ul>");
}
else
{
oStringBuilder.AppendLine("<ul>");
}
if (drParentMenu.Length > 0)
{
foreach (DataRow dr in drParentMenu)
{
string MenuURL = dr["LinkToPage"].ToString();
string MenuName = dr["MenuName"].ToString();
string line = String.Format(@"<li><a href="">{1}</a>", MenuURL, MenuName);
oStringBuilder.Append(line);
string MenuID = dr["MenuID"].ToString();
string ParentID = dr["ParentMenuID"].ToString();
FixedMenuFlg=dr["FixedMenuFlg"].ToString();
DataRow[] subMenu = oDataTable.Select(String.Format("ParentMenuID = {0}", MenuID));
if (subMenu.Length > 0 && !MenuID.Equals(ParentID))
{
var subMenuBuilder = new StringBuilder();
oStringBuilder.Append(GenerateMenu(subMenu, oDataTable, subMenuBuilder));
oStringBuilder.Append("</li>");
}
else
{
if (FixedMenuFlg == "Y")
{
}
else
{
/*** Here i need to accept the value ***/
}
}
}
}
oStringBuilder.Append("</ul>");
return oStringBuilder.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//String userid = Session["UserID"].ToString();
DataTable oDataTable = new DataTable();
oDataTable = SelectDataTable("SELECT * FROM MstModules Where MstModules.ActiveFlg='Y' And (MstModules.FixedMenuFlg='Y' Or MstModules.ParentMenuID=0 Or Exists (SELECT MstUserGroupDetails.* FROM MstUserGroupDetails RIGHT OUTER JOIN MstUserDetails ON MstUserGroupDetails.UserGroupID = MstUserDetails.UserGroupID AND MstUserGroupDetails.CompanyCode = MstUserDetails.CompanyCode Where MstUserDetails.UserID=1 And MstUserGroupDetails.MenuID=MstModules.MenuID And MstUserGroupDetails.AllowAccessFlg='Y')) Order By MstModules.Priority");
//if (oDataTable.Rows.Count > 0)
//{
// con.getData("select * from MstModules where LinktoFlg='#' and MenuID=ParentMenuID");
// if (con.dt.Rows.Count > 0)
// {
// }
//}
//else
//{
//}
DataRow[] drParentMenu = oDataTable.Select("ParentMenuID = 0");
var oStringBuilder = new StringBuilder();
oStringBuilder.Append("<div>");
string MenuList = GenerateMenu(drParentMenu, oDataTable, oStringBuilder) + "</div>";
Literal1.Text = MenuList;
}
}</ul>
推荐答案
StringBuilder sb = new StringBuilder("This is test");
sb.Append("Apple");
sb.ToString();
谢谢
Thanks
.ToString ()
方法
这篇关于是否有可能从stringbuilder获取当前值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!