dev中gridview控件 z

dev中gridview控件 z,第1张

dev中gridview控件 z 目录:

一、客户端常用
1.常用API
2.聚焦行变更事件
3.客户端选择多行
4.客户端选择行
5. 获取选择的行数目
6.单击行时,选中行
7.通过checkbox 选择行
8.选择所有行
9.启动编辑框,Container.VisibleIndex 获取行索引
10.启动服务器端函数:

二、客户端常用事件


三、服务器端常用属性


四、服务器端常用方法


五、服务器端常用事件


六、列的设置
1.模板列使用超链接
2.模板列使用Button用法
3. 使用命令列


七、其他

------------------------
------------------------
内容:
一客户端常用
1.常用API:
  PerformCallback(this.value);
    CollapseAll()
    ExpandAll()
    SelectRows()
    UnselectRows()
    UnselectAllRowsOnPage()
    SelectAllRowsOnPage(this.checked)

2.聚焦行变更事件。


向服务器查询聚焦行的 "EmployeeID" 和 "Notes" 信息,并该信息将返回到 OnGetRowValues() 函数
 function OnGridFocusedRowChanged() {
        grid.GetRowValues(grid.GetFocusedRowIndex(), 'EmployeeID;Notes', OnGetRowValues);
    }
    // 处理服务器端传回的数据(values是个数组,包含 "EmployeeID" 和 "Notes" 值)
    function OnGetRowValues(values) {
        DetailImage.SetImageUrl("FocusedRow.aspx?Photo=" + values[0]);
        DetailNotes.SetText(values[1]);
    }
 <ClientSideEvents FocusedRowChanged="function(s, e) { OnGridFocusedRowChanged(); }"/>

3.客户端选择多行
  function grid_SelectionChanged(s, e) {
        s.GetSelectedFieldValues("ContactName", GetSelectedFieldValuesCallback);
    }
    function GetSelectedFieldValuesCallback(values) {   
        selList.BeginUpdate();
        try {
            selList.ClearItems();
            for(var i = 0; i < values.length; i ++) {
                selList.AddItem(values[i]);
            }
        } finally {
            selList.EndUpdate();
        }
        document.getElementById("selCount").innerHTML = grid.GetSelectedRowCount();
    }
  <ClientSideEvents SelectionChanged="grid_SelectionChanged" />

4.客户端选择行
function OnGridFocusedRowChanged()
    {
        // Query the server for the "EmployeeID" and "Notes" fields from the focused row
        // The values will be returned to the OnGetRowValues() function
        grid.GetRowValues(grid.GetFocusedRowIndex(), 'EmployeeID;Notes', OnGetRowValues);
    }
    //Value array contains "EmployeeID" and "Notes" field values returned from the server
    function OnGetRowValues(values)
    {
        var notes = document.getElementById("detailnotes");
        notes.value = values[1];
        var image = document.getElementById("detailimage");
        image.src = "FocusedRow.aspx?Photo=" + values[0];
    }

5. 获取选择的行数目  grid.GetSelectedRowCount()

6.单击行时,选中行
function OnRowClick(e) {
    //Clear the text selection
    _aspxClearSelection();
    //Unselect all rows
    grid._selectAllRowsOnPage(false);
    //Select the row
    grid.SelectRow(e.visibleIndex, true);
}
 <ClientSideEvents RowClick="function(s, e) { OnRowClick(e); }" />

7.通过checkbox 选择行  设置GridView 的属性ShowSelectCheckBox =true
function grid_SelectionChanged(s,e) {
            s.GetSelectedFieldValues("ContactName",GetSelectedFieldValuesCallback);
        }
GetSelectedFieldValuesCallback 回调函数

function GetSelectedFieldValuesCallback(values) {
            selList.BeginUpdate();
            try {
                selList.ClearItems();
                for(var i=0;i<values.length;i++) {
                    selList.AddItem(values[i]);
                }
            } finally {
                selList.EndUpdate();
            }
            document.getElementById("selCount").innerHTML=grid.GetSelectedRowCount();
        }

selList 是ASPxListBox控件

8.选择所有行: grid.SelectAllRowsOnPage(this.checked);

9.grid.StartEditRow(VisibleIndex) 启动编辑框,Container.VisibleIndex 获取行索引
<dxwgv:GridViewDataColumn FieldName="CustomerID" VisibleIndex="0">
                <DataItemTemplate>
                    <%#GetEditRowHtml(Container.VisibleIndex) %>  GetEditRowHtml 为后台一个方法返回一个字符串
                </DataItemTemplate>
            </dxwgv:GridViewDataColumn>
protected string GetEditRowHtml(int visibleIndex) {
        string rowValue = Convert.ToString(grid.GetRowValues(visibleIndex, "Country"));
        string cbValue = Convert.ToString(cbCountries.Value);
        if(rowValue == cbValue)
            return string.Format("<a href='JavaScript:grid.StartEditRow({0})'> Edit </a>", visibleIndex);
        return "Read Only";
    }

10.启动服务器端函数:  _CustomerCallBack()
  PerformCallback(parameter)


二、客户端常用事件
1.
<ClientSideEvents FocusedRowChanged="function(s, e) { OnGridFocusedRowChanged(); }"/>
2.
 <ClientSideEvents SelectionChanged="grid_SelectionChanged" />

3.
 <ClientSideEvents RowClick="function(s, e) { OnRowClick(e); }" />


三、服务器端常用属性


四、服务器端常用方法
1.获取指定行的数据
object masterKeyValue = masterGrid.GetRowValues(Convert.ToInt32(e.Parameters), "CategoryID");

2.查找包含在gridview中的控件
 grid.FindRowTemplateControl(e.VisibleIndex,"id");
 grid.FindRowCellTemplateControl(e.VisibleIndex, null, "id");
 Label label = grid.FindRowCellTemplateControl(e.VisibleIndex, null, "changePercent") as Label;


六、服务器端常用事件

1.行创建时执行事件
 protected void grid_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
    {
         e.Row.Cells[0].Enabled = false;
 e.GetValue("Change")    decimal change = (decimal)e.GetValue("Change");


2.动态设置每个单元格的显示内容:
 protected void grid_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)

 e.Column.FieldName 
  e.DisplayText 
}
3.编辑事件
 protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)

4. protected void grid_BeforeColumnSortingGrouping(object sender, ASPxGridViewBeforeColumnGroupingSortingEventArgs e)
    {
        BindGrid();
    }


六、列的设置
1.模板列使用超链接
a.<dxwgv:GridViewDataColumn Caption=" " Width="64px">
                <DataItemTemplate>
                    <a href="javascript:showEditForm('<%# Container.KeyValue.ToString() %>');">编辑</a>
                    <a href="javascript:deleteRow('<%# Container.KeyValue.ToString() %>');">删除</a>
                </DataItemTemplate>
                <Settings AllowDragDrop="False" />
            </dxwgv:GridViewDataColumn>

b.<dxwgv:GridViewDataColumn Caption="单号" FieldName="note_id">
            <DataItemTemplate>
            <a href="VisitorNoteDetail.aspx?note_id=<%#Eval("note_id") %>"><%#Eval("note_id") %></a>
            </DataItemTemplate>
            </dxwgv:GridViewDataColumn>

c.<dxwgv:GridViewDataHyperLinkColumn Caption="单据ID" FieldName="note_id" Width="80px"
                VisibleIndex="2">
               
<PropertiesHyperLinkEdit TextFormatString="note_id"
NavigateUrlFormatString="VisitorNoteDetail.aspx?id={0}">
                </PropertiesHyperLinkEdit>
            </dxwgv:GridViewDataHyperLinkColumn>

2.模板列使用Button用法
a. 前台代码:
  <dxwgv:GridViewDataColumn Caption="审批" Width="110" VisibleIndex="1">
                <DataItemTemplate>
                    <div style="float: left; padding-right:3px;">
                        <dxe:ASPxButton ID="btAllow" runat="server" Text="通过" CommandName="Allow"  CommandArgument='<

%#Eval("note_id")%>'>
                        <ClientSideEvents Click="function(s,e) {if(!confirm('确定审批该单据吗?'))

{e.processOnServer=false;}}" />
                        </dxe:ASPxButton>
                    </div>
                    <dxe:ASPxButton ID="btRefuse" runat="server" Text="拒绝" CommandName="Refuse" CommandArgument='<%#Eval

("note_id")%>' >
                        <ClientSideEvents Click="function(s,e) {if(!confirm('确定审批该单据吗?'))

{e.processOnServer=false;}}" />
                    </dxe:ASPxButton>
                </DataItemTemplate>
            </dxwgv:GridViewDataColumn>

b.后台代码:(事件:grid_RowCommand)
 
 protected void grid_RowCommand(object sender, ASPxGridViewRowCommandEventArgs e)
    {
       
        ASPxButton button=e.CommandSource as ASPxButton;
        int noteID = Convert.ToInt32(button.CommandArgument.ToString());
        if (button.CommandName == "Allow")
        {
            ApproveNote(noteID, 1, 1);
          
        }
        else
        {
            ApproveNote(noteID, 2, 0);
        }
        BindGrid();
    }

3. 使用命令列
 a.<%--<dxwgv:GridViewCommandColumn Caption="审批" ButtonType="Button" Width="80px" VisibleIndex="1">
                <CustomButtons>
                    <dxwgv:GridViewCommandColumnCustomButton ID="Allow" Text="通过">
                    </dxwgv:GridViewCommandColumnCustomButton>
                    <dxwgv:GridViewCommandColumnCustomButton ID="Refuse" Text="拒绝">
                    </dxwgv:GridViewCommandColumnCustomButton>
                </CustomButtons>
            </dxwgv:GridViewCommandColumn>--%>

后台事件是:_CustomerCallBack

b. <dxwgv:GridViewCommandColumn ShowSelectCheckbox="true"  Width="30px"  VisibleIndex="1"  >
                <HeaderTemplate>
                    <input type="checkbox" onclick="grid.SelectAllRowsOnPage(this.checked);" title="选择/放弃选择本页的所有

行" />
                </HeaderTemplate>
                <HeaderStyle HorizontalAlign="Center" />
            </dxwgv:GridViewCommandColumn>

后台获取选择行的方法: List<object> noteIds=grid.GetSelectedFieldValues("note_id");


七、其他
1.ASPxGridView 排序方法
 private string GetSort()
    {
        string sortID = "";
        if (grid.GetSortedColumns().Count > 0)
        {
            GridViewDataColumn c = grid.GetSortedColumns()[0];
            sortID = c.FieldName + (c.SortOrder == ColumnSortOrder.Descending ? " DESC" : " ASC");
        }
        return sortID;

}
对应的ASPxGridView 后台事件:
 protected void grid_BeforeColumnSortingGrouping(object sender, ASPxGridViewBeforeColumnGroupingSortingEventArgs e)
    {
        BindGrid();
    }

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/586840.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存