[全選]按鈕: //全選 protected void btnAllCh_Click(object sender, EventArgs e) { foreach(GridViewRow currow in grvInfo.Rows) { ((CheckBox)currow.Cells[0].Controls[1]).Checked = true; } }類似的[取消全選]的編碼為: // 取消全選 protected void btnNoCh_Click(object sender, EventArgs e) { foreach (GridViewRow currow in grvInfo.Rows) { ((CheckBox)currow.Cells[0].Controls[1]).Checked = false; } }[明細]按鈕:該按鈕的操作,要寫在GridView ROW按鈕事件--- RowCommand // GridView ROW按鈕事件 RowCommand protected void grvInfo_RowCommand(object sender, GridViewCommandEventArgs e) { if(e.CommandName.Equals("mingxin")) { ImageButton lb = (ImageButton)e.CommandSource; GridViewRow curgvr = (GridViewRow)lb.Parent.Parent; string paraValue = curgvr.Cells[2].Text.ToString(); //RegisterClientScriptBlock("openmingxin", "<script language='javascript'>window.open(src='mingxin.aspx?pihao="+ paraValue+"','newwindow','');</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "aa", "<script language='javascript'>alert("+paraValue +"');</script>"); } } [刪除]按鈕:可以在HTML原始檔中加上<asp:BoundField HeaderText="審核" /><asp:TemplateField HeaderText="刪除"><ItemStyle HorizontalAlign="Center" /> <ItemTemplate><asp:ImageButton runat="server" ImageUrl="~/image/del.JPG" ID="delid" CommandName="del" OnClientClick="return confirm('確實要刪除嗎?');" /></ItemTemplate></asp:TemplateField>同時也可以如[明細]按鈕在GridView ROW按鈕事件--- RowCommand 對[刪除]點擊按鈕的事件進行服務器端處理!
posted on 2006-02-09 17:29 freeliver54 阅读(583) 评论(4) 编辑 收藏 引用 网摘 所属分类: VS技術實踐
<script type="text/javascript"> // </script>#region gv_showResult 数据绑定时的事件 /// <summary> /// gv_showResult 数据绑定时的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gv_showResult_RowDataBound(object sender, GridViewRowEventArgs e) { //设定宽度 e.Row.Cells[0].Width = 240; e.Row.Cells[1].Width = 340; if (e.Row.RowIndex == -1) return; //加载鼠标单击事件 string strID = e.Row.Cells[0].Text.Trim(); string strName = e.Row.Cells[1].Text.Trim(); string strJS = "document.all.txt_ID.value='" + strID + "';"; strJS += "document.all.hidtxt_ID.value='" + strID + "';"; strJS += "var tmpName = escape('" + strName + "');"; strJS += "document.all.txt_Name.value=unescape(tmpName);"; //加载点击后 变色 strJS += "OnSelectBgColor(this,gv_showResult)"; e.Row.Attributes.Add("onclick", strJS); e.Row.Attributes.Add("onmouseover", "mouseover(this);"); e.Row.Attributes.Add("onmouseout", "mouseout(this,gv_showResult);"); } #endregion
回复 更多评论一般情况下GridView 隐藏列 <Columns> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="hidtxt_currID" runat="server" Text='<%# Bind("currID") %>' style="display:none"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> 后台抓值 string strCurrID = ((TextBox)this.gv_Selected.Rows[i].Cells[0].FindControl("hidtxt_currID")).Text.Trim(); 回复 更多评论
ajax情况下GridView 隐藏列 <Columns> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="hidtxt_currID" runat="server" Text='<%# Bind("currID") %>' style="display:none"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> 注意<HeaderTemplate>也需要display:none 后台抓值 string strCurrID = ((TextBox)this.gv_Selected.Rows[i].Cells[0].FindControl("hidtxt_currID")).Text.Trim(); 回复 更多评论
自定义数据绑定: VS2003 DataGrid 的 ItemDataBound 事件: e.Item.Cells[0].Text=((String)DataBinder.Eval(e.Item.DataItem, "Name")); VS2005 GridView 的 RowDataBound 事件: if (e.Row.RowIndex >= 0) { DropDownList tmpDrpSex = (DropDownList)e.Row.FindControl("drp_Sex"); tmpDrpSex.Items.Clear(); tmpDrpSex.Items.Add(new ListItem("女","0")); tmpDrpSex.Items.Add(new ListItem("男","1")); tmpDrpSex.SelectedValue = DataBinder.Eval(e.Row.DataItem, "ASex").ToString(); } 回复 更多评论
# re: VS2005中GridView簡單應用 2006-12-30 19:04 freeliver54