问题描述
现在我已经把ListBox控件放在DateGrid的EditItemTemplate里了,按编辑即可以绑定并显示出来,但是值无法指定上,因为我想把多个值3,4,5这种依次查找如果匹配则选择上相应的项,不知道该怎么办<EditItemTemplate><asp:ListBoxid=ListBox1runat="server"DataTextField="kname"DataSource="<%#showdeptList()%>"SelectionMode="Multiple"DataValueField="id"Rows="10"></asp:ListBox></EditItemTemplate>
解决方案
解决方案二:
WebControlusingSystem;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Globalization;namespaceRisen.Web.UI.WebControls{///<summary>///GroupRadioButtoncontrolisastandardradio-buttonwiththeextended///abilitiestobeusedingroups.///</summary>///<remarks>///Standard<seecref="System.Web.UI.WebControls.RadioButton"/>controls///cannotbegroupedwhenareplacedatthedifferentrowsoftheDataGrid,///DataList,Repeater,etc.controls.//////The"name"attributeoftheradiobuttonHTMLcontrolthatisrendered///atthewebformafterRadioButtoncontrolhasbeenexecutedisdepend///ontheUniqueIDoftheRadioButton.Soforthedifferentrowsofthe///DataGrid/DataList/Repeatertheseattributesaredifferentandradio///buttonsdonotbelongtothesamegroup.///</remarks>[ToolboxData("<{0}:GroupRadioButtonrunat=server></{0}:GroupRadioButton>")]publicclassGroupRadioButton:RadioButton,IPostBackDataHandler{publicGroupRadioButton():base(){}#regionPropertiesprivatestringValue{get{stringval=Attributes["value"];if(val==null)val=UniqueID;elseval=UniqueID+"_"+val;returnval;}}#endregion#regionRenderingprotectedoverridevoidRender(HtmlTextWriteroutput){RenderInputTag(output);}privatevoidRenderInputTag(HtmlTextWriterhtw){htw.AddAttribute(HtmlTextWriterAttribute.Id,ClientID);htw.AddAttribute(HtmlTextWriterAttribute.Type,"radio");htw.AddAttribute(HtmlTextWriterAttribute.Name,GroupName);htw.AddAttribute(HtmlTextWriterAttribute.Value,Value);if(Checked)htw.AddAttribute(HtmlTextWriterAttribute.Checked,"checked");if(!Enabled)htw.AddAttribute(HtmlTextWriterAttribute.Disabled,"disabled");stringonClick=Attributes["onclick"];if(AutoPostBack){if(onClick!=null)onClick=String.Empty;onClick+=Page.GetPostBackClientEvent(this,String.Empty);htw.AddAttribute(HtmlTextWriterAttribute.Onclick,onClick);htw.AddAttribute("language","javascript");}else{if(onClick!=null)htw.AddAttribute(HtmlTextWriterAttribute.Onclick,onClick);}if(AccessKey.Length>0)htw.AddAttribute(HtmlTextWriterAttribute.Accesskey,AccessKey);if(TabIndex!=0)htw.AddAttribute(HtmlTextWriterAttribute.Tabindex,TabIndex.ToString(NumberFormatInfo.InvariantInfo));htw.RenderBeginTag(HtmlTextWriterTag.Input);htw.RenderEndTag();}#endregion#regionIPostBackDataHandlerMembersvoidIPostBackDataHandler.RaisePostDataChangedEvent(){OnCheckedChanged(EventArgs.Empty);}boolIPostBackDataHandler.LoadPostData(stringpostDataKey,System.Collections.Specialized.NameValueCollectionpostCollection){boolresult=false;stringvalue=postCollection[GroupName];if((value!=null)&&(value==Value)){if(!Checked){Checked=true;result=true;}}else{if(Checked)Checked=false;}returnresult;}#endregion}}
解决方案三:
保证好使
解决方案四:
UP
解决方案五:
看不懂啊,这个怎么用啊
解决方案六:
ListBox1.Itmes[序号].Selected=true设置单项,你自己判断条件满足的就设置Selected=true就可以了。如:ListBox1.Itmes[0].Selected=trueListBox1.Itmes[2].Selected=true则第0列和第2列为选中
解决方案七:
上面是一个自定义组件