不能上图,只能手打!
编号 二级分类 一级分类 操作
-----------------------------------------------------
1 牛仔裤 裤子 编辑
2 T恤 衣服 编辑
-----------------------------------------------------
这是一个GridView绑定的数据,一级分类是一个DropDownList,有两个值,第一个是衣服,第二个是裤子。
当我点击编辑的时候,下拉列表显示的都是第一个值:衣服,如何让下拉列表的值显示为我当前的值?
在什么事件里面写?
新手搞不定啊!求大师赐教!谢谢
------解决方案--------------------------------------------------------
我是在EditItemTemplate入一个DropDownList 和一个HiddenField ,其中HiddenField 绑定数据库的值,然后在绑定时再把HiddenField的值 附给 DropDownList
- HTML code
<ItemTemplate> <%# Galsun.stgj.Bll.Shop.GetInfoByID(Convert.ToInt32(Eval("ShopID"))).Title%> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="item_ddl_ShopID" runat="server"> </asp:DropDownList> <asp:HiddenField ID="item_hf_ShopID" Value=<%# Eval("ShopID") %> runat="server" /> </EditItemTemplate>
------解决方案--------------------------------------------------------
- C# code
protected void dv1_RowDataBound(object sender, GridViewRowEventArgs e) { TextBox txt; TextBox txtSm; ImageButton Btn; if (e.Row.RowType == DataControlRowType.DataRow) { Btn = (ImageButton)e.Row.FindControl("btnDelete"); Btn.Attributes.Add("onclick", "return confirm('提示:\\n确定要删除吗?');"); txt = (TextBox)e.Row.FindControl("dqbh"); txt.Style.Add("ime-mode", "disabled");//当前文本框中文输入法控制。 txt.Attributes.Add("onkeyup", "with(window.event) if (event.keyCode == 13) return; this.value=this.value.replace(/[^0-9.]/gi,'');"); txtSm = (TextBox)e.Row.FindControl("sm"); txtSm.Style.Add("ime-mode", "disabled"); //声码文本的实例和其他的必须同时存在,所以名称不能相同 //增加事件,onkeydown,声码文本框的内容等于此文本框的pinyin,pinyin是自动获取 txt = (TextBox)e.Row.FindControl("dm"); txt.Attributes.Add("onkeydown", "with(window.event) if (keyCode==13){document.getElementById('" + txtSm.ClientID + "').value = pinyin.go(document.getElementById('" + txt.ClientID + "').value);}"); } else if (e.Row.RowType == DataControlRowType.Footer) { txt = (TextBox)e.Row.FindControl("dqbh1"); txt.Style.Add("ime-mode", "disabled"); txt.Attributes.Add("onkeyup", "with(window.event) if (event.keyCode == 13) return; this.value=this.value.replace(/[^0-9.]/gi,'');"); strControlClientID = txt.ClientID; PublicFunction.InitFocus(this, strControlClientID); txt = (TextBox)e.Row.FindControl("xian1"); Btn = (ImageButton)e.Row.FindControl("btnAdd"); txt.Attributes.Add("onkeydown", "with(window.event) if (keyCode==13){document.getElementById('" + Btn.ClientID + "').click();}"); txtSm = (TextBox)e.Row.FindControl("sm1"); txtSm.Style.Add("ime-mode", "disabled"); txt = (TextBox)e.Row.FindControl("dm1"); txt.Attributes.Add("onkeydown", "with(window.event) if (keyCode==13){document.getElementById('" + txtSm.ClientID + "').value = pinyin.go(document.getElementById('" + txt.ClientID + "').value);}"); } }