ASP.NET GridView控件匯出EXCEL-移除控件,只是顯示文本
ASP.NET GridView控件匯出EXCEL-移除控件,只是顯示文本
下午 05:10 2011/2/22
將GridView中的TextBox,DropDownList,LinkButton去掉,顯示文本。
??? public void ClearGridControls(ref Control sourceControl)
??? {
??????? for (int i = sourceControl.Controls.Count - 1; i >= 0; i += -1)
??????? {
??????????? Control control = sourceControl.Controls[i];
??????????? ClearGridControls(ref control);
??????? }
??????? if (!(sourceControl is TableCell))
??????? {
??????????? Literal literal;
??????????? if (sourceControl.GetType().GetProperty("SelectedItem") != null)
??????????? {
??????????????? //
??????????????? // 下拉框
??????????????? //
??????????????? literal = new Literal();
??????????????? // 顯示文本
??????????????? sourceControl.Parent.Controls.Add(literal);
??????????????? // 取內(nèi)容
??????????????? literal.Text = Convert.ToString(sourceControl.GetType().GetProperty("SelectedItem").GetValue(sourceControl, null));
??????????????? // 移除
??????????????? sourceControl.Parent.Controls.Remove(sourceControl);
??????????? }
??????????? else if (sourceControl.GetType().GetProperty("Text") != null)
??????????? {
??????????????? //
??????????????? // 文本框
??????????????? //
??????????????? literal = new Literal();
??????????????? sourceControl.Parent.Controls.Add(literal);
??????????????? literal.Text = Convert.ToString(sourceControl.GetType().GetProperty("Text").GetValue(sourceControl, null));
??????????????? sourceControl.Parent.Controls.Remove(sourceControl);
??????????? }
??????? }
??? }
轉(zhuǎn)載于:https://www.cnblogs.com/htht66/archive/2011/02/22/1961499.html
總結(jié)
以上是生活随笔為你收集整理的ASP.NET GridView控件匯出EXCEL-移除控件,只是顯示文本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转]C/C++ 文件读写操作总结
- 下一篇: javascript:设置URL参数的方