如何使用gridview列中的数据集列作为行绑定条件 [英] How to use dataset column that is not a bound field in gridview for rowbound condition

查看:74
本文介绍了如何使用gridview列中的数据集列作为行绑定条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有绑定字段列的gridview。我的问题是如何将数据用于不是绑定字段的条件。例如,查询是:



从表中选择a1,a2,a3,a4;



但是只有a1,a2,a3是绑定字段,只需要显示它们。但是a4字段的值将用作rowDataBound事件的条件。那么我们如何在rowDataBound事件{code}中为每一行检索字符串中的a4数据?



我正在使用数据集将数据绑定到griview。



谢谢.. !!



我尝试过:



尝试使用viewstate进行数据集但不起作用。

Hi,

I have gridview with bound field columns. My question is how can I use data for condition that is not a bound field. For example, query is:

Select a1,a2,a3,a4 from table;

But only a1,a2,a3 are bound fields and they are only required to be shown. But value of a4 field is to be used as condition for rowDataBound event. Then how can we retrieve a4 data in a string for each row in rowDataBound event{code}??

I am using dataset to bind data to griview.

Thank You..!!

What I have tried:

tried using viewstate for dataset but it is not working.

推荐答案

试试这个,

创建一个css类来隐藏列

try this,
create a css class to hide the column
<style>
       .hide {
           display:none
       }
   </style>





将css类分配给 ItemStyle HeaderStyle



Assign the css class to the ItemStyle and HeaderStyle

<asp:GridView  ID="GridView1" AutoGenerateColumns="false" runat="server" OnRowDataBound="GridView1_RowDataBound">
               <Columns>

                   <asp:BoundField DataField="a1" HeaderText="a1" />
                    <asp:BoundField DataField="a2"  HeaderText="a2" />
                    <asp:BoundField DataField="a3"  HeaderText="a3" />
                   <asp:BoundField DataField="a4" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" />

               </Columns>
           </asp:GridView>





现在你可以用<$获得价值c $ c> RowDatabound 活动





Now you can get the value in RowDatabound event

protected void Page_Load(object sender, EventArgs e)
       {
           DataTable dt = new DataTable();
           dt.Columns.Add("a1");
           dt.Columns.Add("a2");
           dt.Columns.Add("a3");
           dt.Columns.Add("a4");
           dt.Rows.Add(1, 2, 3, 4);
           dt.Rows.Add(11, 22, 33, 44);
           GridView1.DataSource = dt;
           GridView1.DataBind();
       }

       protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               string a1 = e.Row.Cells[0].Text;
               string a2 = e.Row.Cells[1].Text;
               string a3 = e.Row.Cells[2].Text;
               string a4 = e.Row.Cells[3].Text;

           }
       }


c# - 如何隐藏列但仍然可以访问其值? - 堆栈溢出 [ ^ ]





此链接帮助了我。
c# - How to hide a column but still access its value? - Stack Overflow[^]


this link helped me.


这篇关于如何使用gridview列中的数据集列作为行绑定条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆