Client Side Evaluation of Gridview
2011-08-29 16:28
399 查看
Following is the structure of sample data table with UserName, Ismale and IsActive column that have string, Boolean, Boolean data respectively.
//Creation of static datatable
DataTable dt = new DataTable();
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("IsMale", typeof(bool));
dt.Columns.Add("IsActive", typeof(Boolean));
Following is the sample data for the above datatable which we will bind to the gridview at server side.
dt.Rows.Add("Dharmedra","true","true");
dt.Rows.Add("Katrina", "false", "true");
dt.Rows.Add("Sunny", "true", "false");
dt.Rows.Add("Baba ramdev", "true", "true");
dt.Rows.Add("Sanjay dutt", "true", "false");
dt.Rows.Add("Kareena kapoor", "false", "false");
Following is the way we bind the datatable to the gridview:
//Binding static datatable to the gridview
dgv.DataSource = dt;
dgv.DataBind();
Now the main task we have to do is the client side evaluation of the datatable bound to the gridview.
Following is the gridview we created using aspx page. The lines highlighted with yellow color are the controls used in the itemtemplate section gridview control. These three control evaluate the data of the grid at the client side.
<asp:GridView ID="dgv" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
CssClass="GridViewStyle" GridLines="None" Width="100%">
<Columns>
<asp:TemplateField HeaderText="Name">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<th align="left" width="60%">
<asp:Label runat="server" ID="Label1" Text='User Name'></asp:Label>
</th>
<th align="center" width="20%">
<asp:Label runat="server" ID="Label2" Text='Is Male?'></asp:Label>
</th>
<th align="center" width="20%">
<asp:Label runat="server" ID="Label3" Text='Is Active?'></asp:Label>
</th>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" width="60%">
<asp:Label runat="server" ID="lbluser" Text='<%#Eval("UserName") %>'></asp:Label>
</td>
<td align="center" width="20%">
<asp:CheckBox runat="server" ID="chk" Checked='<%# Eval("IsMale") %>'></asp:CheckBox>
</td>
<td align="center" width="20%">
<asp:Image runat="server" ID="img" ImageUrl='<%# (Eval("IsActive").ToString().ToLower() == "true" ? "~/Images/Green.png" : "~/Images/Red.png" ) %>' />
</td
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
<asp:Label runat="server" ID="lbluser" Text='<%#Eval("UserName") %>'></asp:Label>
<asp:CheckBox runat="server" ID="chk" Checked='<%# Eval("IsMale") %>'></asp:CheckBox>
<asp:Image runat="server" ID="img" ImageUrl='<%# (Eval("IsActive").ToString().ToLower() == "true" ? "~/Images/Green.png" : "~/Images/Red.png" ) %>' />
In all the above lines
<%#Eval("UserName") %> evaluates the UserName column of the datagrid
<%# Eval("IsMale") %> evaluates the IsMale column
<%# (Eval("IsActive").ToString().ToLower() == "true" ? "~/Images/Green.png" : "~/Images/Red.png" ) %> evaluates the IsActive column and set path for the ImageUrl attribute of the Image control.
//Creation of static datatable
DataTable dt = new DataTable();
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("IsMale", typeof(bool));
dt.Columns.Add("IsActive", typeof(Boolean));
Following is the sample data for the above datatable which we will bind to the gridview at server side.
dt.Rows.Add("Dharmedra","true","true");
dt.Rows.Add("Katrina", "false", "true");
dt.Rows.Add("Sunny", "true", "false");
dt.Rows.Add("Baba ramdev", "true", "true");
dt.Rows.Add("Sanjay dutt", "true", "false");
dt.Rows.Add("Kareena kapoor", "false", "false");
Following is the way we bind the datatable to the gridview:
//Binding static datatable to the gridview
dgv.DataSource = dt;
dgv.DataBind();
Now the main task we have to do is the client side evaluation of the datatable bound to the gridview.
Following is the gridview we created using aspx page. The lines highlighted with yellow color are the controls used in the itemtemplate section gridview control. These three control evaluate the data of the grid at the client side.
<asp:GridView ID="dgv" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
CssClass="GridViewStyle" GridLines="None" Width="100%">
<Columns>
<asp:TemplateField HeaderText="Name">
<HeaderTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<th align="left" width="60%">
<asp:Label runat="server" ID="Label1" Text='User Name'></asp:Label>
</th>
<th align="center" width="20%">
<asp:Label runat="server" ID="Label2" Text='Is Male?'></asp:Label>
</th>
<th align="center" width="20%">
<asp:Label runat="server" ID="Label3" Text='Is Active?'></asp:Label>
</th>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" width="60%">
<asp:Label runat="server" ID="lbluser" Text='<%#Eval("UserName") %>'></asp:Label>
</td>
<td align="center" width="20%">
<asp:CheckBox runat="server" ID="chk" Checked='<%# Eval("IsMale") %>'></asp:CheckBox>
</td>
<td align="center" width="20%">
<asp:Image runat="server" ID="img" ImageUrl='<%# (Eval("IsActive").ToString().ToLower() == "true" ? "~/Images/Green.png" : "~/Images/Red.png" ) %>' />
</td
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="RowStyle" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
<asp:Label runat="server" ID="lbluser" Text='<%#Eval("UserName") %>'></asp:Label>
<asp:CheckBox runat="server" ID="chk" Checked='<%# Eval("IsMale") %>'></asp:CheckBox>
<asp:Image runat="server" ID="img" ImageUrl='<%# (Eval("IsActive").ToString().ToLower() == "true" ? "~/Images/Green.png" : "~/Images/Red.png" ) %>' />
In all the above lines
<%#Eval("UserName") %> evaluates the UserName column of the datagrid
<%# Eval("IsMale") %> evaluates the IsMale column
<%# (Eval("IsActive").ToString().ToLower() == "true" ? "~/Images/Green.png" : "~/Images/Red.png" ) %> evaluates the IsActive column and set path for the ImageUrl attribute of the Image control.
相关文章推荐
- Server side evaluation of Gridview Data
- Client Side Validation of GridView control with javascript
- How to access gridview cell values on client side
- Button的客户端验证(client-side validate of ASP.NET button)
- support Spring for configuration of the JMS client side as well as forJMS Message Broker
- If WCF Service side and Client side config is different?!
- ASP.NET Client Side Callback
- left side of asn-op not an lvalue错误解决方法
- Cross-domain calls and server side debugging of Silverlight application
- 背景建模一篇综述 Evaluation of Background Subtraction Techniques for Video Surveillance
- Using jQuery with Client-Side Data Binding
- [转]ASP.NET AJAX client-side framework failed to load
- ASPxGridView Exception has been thrown by the target of an invocation
- List of FTP Sever/Client Software
- no new variables on left side of :=
- Android完美解决GridView异步加载图片和加载大量图片时出现Out Of Memory问题
- left-to-right evaluation rule and side effect
- The provider is not compatible with the version of Oracle client
- How to get MetaData on client side in WCF?如何在客户端获取WCF service的元数据
- [文献阅读] Bleu: a Method for Automatic Evaluation of Machine Translation