ASP GridView相关问题 本帖最后由 wwp_aptech 于 2011-06-28 00:40:35 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 编辑的时候 先找到模版列中的值 或者索引然后设置编辑模版里的控件(用findcontrol来找) 索引或者值 我是在EditItemTemplate入一个DropDownList 和一个HiddenField ,其中HiddenField 绑定数据库的值,然后在绑定时再把HiddenField的值 附给 DropDownList <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> protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e) { DropDownList ddl = (DropDownList)e.Item.Cells[3].FindControl("item_ddl_ShopID"); if (ddl != null) { foreach (ListItem listtiem in ddl_ShopID.Items) { ddl.Items.Add(listtiem); } HiddenField hf = (HiddenField)e.Item.Cells[3].FindControl("item_hf_ShopID"); ddl.Text = hf.Value; } } 是不是应该设置一下 回发属性??AntoPostback=false 从来不用GridView里面自带的编辑,飘过 在ItemDataBound里面绑定你的方法! 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);}"); } }这事件可以用来为每行的控件赋初值和加入属性等,RowType 判断的是数据行还是表格底部最后一行(脚部),我这个是文本框,dropdownlist一样 下面代码的前两个参数是什么意思啊 ASP.NET实现论坛的头像预览功能 请问有人在项目中用spring.net吗? 救救我!! 数据库问题 关于TEXTBOX,奇怪的现象 在asp.net里面怎样获得文件浏览框??急!!!!!!! c#.如果做关联查询 这个问题题目怎么说呢?还是近来看吧,解决送分^_^ 关于取得DATAGRID控件中某一行行号的问题 关于权限设计的 怎么提高项目的开发效率和准确度
<%# 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> protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
DropDownList ddl = (DropDownList)e.Item.Cells[3].FindControl("item_ddl_ShopID");
if (ddl != null)
{
foreach (ListItem listtiem in ddl_ShopID.Items)
{
ddl.Items.Add(listtiem);
}
HiddenField hf = (HiddenField)e.Item.Cells[3].FindControl("item_hf_ShopID");
ddl.Text = hf.Value;
}
}
{
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);}");
}
}这事件可以用来为每行的控件赋初值和加入属性等,RowType 判断的是数据行还是表格底部最后一行(脚部),我这个是文本框,dropdownlist一样