GridView,repeater整理

来源:互联网 发布:淘宝卖家如何发布宝贝 编辑:程序博客网 时间:2024/05/20 19:19

Datalist数据绑定

普通: 

<%# DataBinder.Eval(Container.DataItem, "itemName")%>或者  <%# Eval("topicContent")%>

A标签:

<a id="atopic" href="CarClubRemarkbefore.aspx?prodId=<%# Eval("prodId")%>" target="_self"></a>

图片:

<img border="0" height="50" src="<%# Eval("prodUrl")%>" width="50" />

按钮:

<asp:button id="btnbook"  runat="server" text="加入购物车

OnClientClick="javascript:return confirm('确认删除吗?')" commandname="book" commandargument='<%#Eval("prodId")%>' />

页面跳带参数跳转:

 <input type="button" value=详情" class="price_btn4" onclick="window.location='CarClubScenicDetail.aspx?prodId=<%# DataBinder.Eval(Container.DataItem, "prodId")%>&prodTypeId=<%# DataBinder.Eval(Container.DataItem, "prodTypeId")%>'" />

翻页插件:

AspNetPager.dllchanagePage.css

gradview,repeater等获取选中行

for (int i = 0; i < rpshopping.Items.Count; i++)

            {

                CheckBox cb = (CheckBox)rpshopping.Items[i].FindControl("cbbox");

                //选?中D

                if (cb.Checked)

                {

                    int a = shoppingCarlst[i].collectId;

                    collects.Add(a);

                    TextBox ClassTitleTextBox = this.rpshopping.Items[i].FindControl("TextBox1"as TextBox;

                    string ClassTitle = ClassTitleTextBox.Text;

                }

            }

gridview 百分比:

 <asp:templatefield headertext="佣金百分比">

                            <ItemTemplate>

                                <%#Eval("CSL_Percent").ToString() + "%"%>

                            </ItemTemplate>

                        </asp:templatefield>

GridView绑定实体类的子实体的字段:

user生成的实体User里包含子实体Role想要绑定RoleName

可以使用如下进行绑定:  

<%# (((User)Container.DataItem).Role).RoleName %>

gridview对应列数据

string a = this.GridView1.Rows[i].Cells[j].Text.ToString();

 textbox.text = a;

通过aspnetpagerDataList分页(插件AspNetPager.dll,chanagePage.css在资源中下载):

前台代码:  

<div id="newslistdiv">

        <asp:DataList ID="rtBusOrder" runat="server" Width="820px">

            <HeaderTemplate>

                </ItemTemplate> </asp:DataList> </div>

    <div>

 <webdiyer:AspNetPager ID="AspNetPager1" CssClass="paipai" CurrentPageButtonClass="cpb"

                    runat="server" PageSize="9" FirstPageText=" 首页" LastPageText=" 尾页" NextPageText=" 下一页"

                    OnPageChanged="AspNetPager1_PageChanged" PrevPageText=" 上?一?页? " AlwaysShow="true">

                </webdiyer:AspNetPager>

                </div>

后台代码:

            //翻页代码      

           this.AspNetPager1.RecordCount = UserOrderAll.Count;

            PagedDataSource pds = new PagedDataSource();    //定义一个PagedDataSource类来执行分页功能

            pds.DataSource = UserOrderAll;

            pds.AllowPaging = true;

            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;

            pds.PageSize = AspNetPager1.PageSize;

            AspNetPager1.CurrentPageButtonPosition = Wuqi.Webdiyer.PagingButtonPosition.Center;

            //绑定表

            rtBusOrder.DataSource = pds;

            rtBusOrder.DataBind();

GridView的RowDataBound事件:

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

        {

            //隐藏列

            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)

            {

                e.Row.Cells[0].Visible = false;

            }

            //执行循环,保证每条数据都能更新

            if (e.Row.RowType == DataControlRowType.DataRow)

            {

                //当鼠标停留时更改背景色

                e.Row.Attributes.Add("onmouseover""c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");

                //当鼠标移开时还原背景色

                e.Row.Attributes.Add("onmouseout""this.style.backgroundColor=c");

                //鼠标放上时是小手指

                e.Row.Attributes["style"] = "cursor:hand";

                //点击鼠标打开页面

                e.Row.Attributes.Add("onclick""window.open('CompanyUpdate.aspx?CompanyID=" + e.Row.Cells[0].Text.ToString() + "','newwindow','toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no,top=280,left=450,width=1000,height=500')");

            }

            if (e.Row.RowState == DataControlRowState.Edit)

            { //编辑状态

                e.Row.Attributes.Remove("onclick");

                e.Row.Attributes.Remove("ondblclick");

                e.Row.Attributes.Remove("style");

                e.Row.Attributes["title"] = "编辑行";

                

            }

        }