本文介绍了使用下拉列表在代码隐藏中创建htmltable,并在运行时分配其选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在codebind中创建了动态htmltable



源页面

Hi,
I have created dynamically htmltable in codebind as

source page

<div id="bindHTMLhere"  runat="server" />





和代码隐藏



and in codebehind

 tblString.Append(" <tr>");
  for (int i = 0; i < 3; i++)
                      {
tblString.Append("<td >");
tblString.Append("   <select value='" + dataPO.Tables[2].Rows[i]["add_less"].ToString().TrimStart().TrimEnd() + "' id='ddlAddLess_Row1' TabIndex='" + (++ddlindex) + "' runat='server' style='width:10%;height:23px;'  onkeyup='toUnicode(this,event)' class='Assettextbox'></select>");
 tblString.Append("    </td>");
                     }
  tblString.Append(" </tr>");







bindHTMLhere.InnerHtml = tblString.ToString();





我想将此下拉列表(选择)与数据库绑定,并且还想设置其选定的值。 />






请帮助



I want to bind this dropdown (select) with the database and also want to set its selected value .



Please help

推荐答案

string ChoiceHtml = "";

for(var i=0;i<dataPO.Tables[2].Rows.Count;i++)
{
  var valField = dataPO.Tables[2].Rows[i]["ValueField"];
  var txtField = dataPO.Tables[2].Rows[i]["TextField"];
  if(dataPO.Tables[2].Rows[i]["add_less"]==1)
  {
    ChoiceHtml += "<option selected = 'true' value="+ valField +"> " + txtField   +" </option>";
  } 
  else
  {
    {
    ChoiceHtml += "<option value="+ valField +"> " + txtField   +"   </option>";
  } 
  }
  
}





在重新选择交换时选择属性选项,并重新分配html字符串为



at the time of re select exchange "Selected" property for option , and re assign html string as

tblString.Append("   <select value='" + dataPO.Tables[2].Rows[i]["add_less"].ToString().TrimStart().TrimEnd() + "' id='ddlAddLess_Row1' TabIndex='" + (++ddlindex) + "' runat="'server'" style='width:10%;height:23px;'  onkeyup='toUnicode(this,event)' class='Assettextbox'>"+ ChoiceHtml   +"</select>");
 tblString.Append("    ");

 bindHTMLhere.InnerHtml = tblString.ToString();











谢谢






Thanks


这篇关于使用下拉列表在代码隐藏中创建htmltable,并在运行时分配其选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 16:21