Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / WebDataGrid and SelectedRow Server Side
WebDataGrid and SelectedRow Server Side
New DiscussionHow can I access the the rows selected in a WebDataGrid on the server side?
For example, I have a WebDataGrid and I've enabled the Selection behavior fot it. I want the user to be able to select a row in the WebDataGrid then click a button which calls server side code to process the selected row (i.e. getting the values of some of the columns of the selected row).
I think I need to use the SelectedRowsCollection somehow, but not sure how to use it with my WebDataGrid.
Thanks,
John
Replies
-
0
Hi John,
It's off the Selection behavior:
grid.Behaviors.Selection.SelectedRows;-
0
Alex,
I'm one step closer, but I can't seem to read the records in the SelectedRows collection. Here's my sample code. When I run it, the selectedRow variable returns null. When I'm debugging, I do see one record selected in wdgFabric.Behaviors.Selection.SelectedRows.
Am I doing something wrong?
// inside my button_clicked method – after I've selected a row
string tmp;
if (wdgFabric.Behaviors.Selection.SelectedRows.Count > 0)
{
foreach (GridRecord selectedRow in wdgFabric.Behaviors.Selection.SelectedRows) // errors out here with selectedRow returning null
{
tmp = selectedRow.Items.GetValue(1).ToString();
foreach (GridRecordItem selectedRowItem in selectedRow.Items)
{
Label2.Text = selectedRowItem.Text.ToString();
}
}
}-
0
I tried out similar code in a quick sample
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="Infragistics35.Web.v8.3, Version=8.3.20083.1, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Behaviors>
<ig:Selection CellClickAction="Row" RowSelectType="Multiple">
</ig:Selection>
</Behaviors>
<Columns>
<ig:BoundDataField DataFieldName="CustomerID" Key="CustomerID">
<Header Text="CustomerID" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="CompanyName" Key="CompanyName">
<Header Text="CompanyName" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="ContactName" Key="ContactName">
<Header Text="ContactName" />
</ig:BoundDataField>
</Columns>
</ig:WebDataGrid>
<asp:Button runat=server onclick="Unnamed1_Click" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>With the following code behind in the button click
protected void Unnamed1_Click(object sender, EventArgs e)
{
foreach (GridRecord row in this.WebDataGrid1.Behaviors.Selection.SelectedRows)
{
if (row != null)
{
}
}}
and the row was != null in my tests. Could you try a really small sample and see if it works for you?
-
0
I am encountering the same problem. The row is alway, in my case, Nothing. I can assure you that it is really frustrating to do something so simple when it isn't working. I hope you can find my problem.
I pass you the code behind:
Protected Sub lnkbtnEditar_Clicked(ByVal sender As Object, ByVal e As EventArgs)
For Each row As GridRecord In WebDataGrid1.Behaviors.Selection.SelectedRows
If Not (row Is Nothing) Then
Dim iCount As Integer = row.Items.Count
End If
Next
End SubThe aspx page code:
<ig:WebDataGrid ID="WebDataGrid1" runat="server" DataKeyFields="ID" StyleSetName="Claymation" AutoGenerateColumns="False" Width="260px" StyleSetPath="~/ig_res">
<Columns>
<ig:TemplateDataField Key="Año" Width="50px">
<ItemTemplate>
<asp:Label ID="lblAño" runat="server"><%#DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "Año")%></asp:Label>
</ItemTemplate>
<Header Text="Año" />
</ig:TemplateDataField>
<ig:TemplateDataField Key="Fecha inicial" Width="81px">
<ItemTemplate>
<asp:Label ID="lblIniVig" runat="server"><%#DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "IniVig")%></asp:Label>
</ItemTemplate>
<Header Text="Fecha inicial" />
</ig:TemplateDataField>
<ig:TemplateDataField Key="Fecha final" Width="81px">
<ItemTemplate>
<asp:Label ID="lblFinVig" runat="server"><%#DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "FinVig")%></asp:Label>
</ItemTemplate>
<Header Text="Fecha final" />
</ig:TemplateDataField>
</Columns>
<Behaviors>
<ig:Selection RowSelectType="Single" CellClickAction="Row">
<SelectionClientEvents RowSelectionChanged="WebDataGrid1_RowSelectionChanged" />
</ig:Selection>
<ig:Sorting SortingMode="Single" Enabled="true"></ig:Sorting>
</Behaviors>
</ig:WebDataGrid><asp:LinkButton ID="lnkbtnEditar" runat="server" CausesValidation="false" OnClick="lnkbtnEditar_Clicked">Editar</asp:LinkButton>
<script language="javascript" type="text/javascript">
function WebDataGrid1_RowSelectionChanged(webDataGrid, evntArgs) {
//for the moment do nothing
}
</script> -
0
public string GetSelValTemp(WebDataGrid g, string col)
{
if (g.Behaviors.Selection.SelectedRows.Count < 1) return "";
foreach ( GridRecord row in g.Behaviors.Selection.SelectedRows)
{
if (row != null)
{
int countItems = row.Items.Count;for (int i = 0; i < countItems; i++)
{
GridRecordItem gi = row.Items[i];if (F.EqualsIC(gi.Column.Footer.FieldKey, col)) return F.ToString(gi.Text);
}
}
}
return "";
}
the foreach does not work, i think because of the forgotten implementation of ienumerable function.
-
0
Hello,
I have the same issue.
First point
Could you tell me please the equivalance webdatagrid of this line working correctly with a GridView? :
num_oc =long.Parse(GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text);
Second Point
I am not a specialist of Infragistics but I would like to know what is the mean to find in my webdatagrid the value of the first column in the row selected by the user example : 27
In my code below the row is null !!!!!
Thanks
protected void Unnamed1_Click(object sender, EventArgs e)
{
foreach (GridRecord row in this.WebDataGridPlanting.Behaviors.Selection.SelectedRows)
{
if (row != null)
{
int i=+1;
}
}
}
-
0
I am going to ask that someone who is able to reproduce this issue submit an issue to Developer Support so that the issue can be tracked down. Please include a sample project that shows this issue.
I tried this from the code posted in the forum and could not reproduce this behavior.
-
0
I think the reason for getting null for the SelectedRows collection is when using a SQLDataSource as opposed to a dataset to load the WebDataGrid. I loaded data with the SQLDataSource and I can retrieve my selected row fine. When I use a dataset, the selected row is null.
Here's my source that does both the SQLDataSource & DataSet. The WebDataGrid1 uses the SQLDataSource and the WebDataGrid2 uses a dataset.
—————————————————————————————-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %><%@ Register Assembly="Infragistics2.Web.v8.3, Version=8.3.20083.1009, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Behaviors>
<ig:RowSelectors>
</ig:RowSelectors>
<ig:Selection CellClickAction="Row" RowSelectType="Single">
</ig:Selection>
</Behaviors>
<Columns>
<ig:BoundDataField DataFieldName="AssemblyGroup" Key="AssemblyGroup">
<Header Text="AssemblyGroup" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="AssemblyType" Key="AssemblyType">
<Header Text="AssemblyType" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="FullChair" Key="FullChair">
<Header Text="FullChair" />
</ig:BoundDataField>
</Columns>
</ig:WebDataGrid>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SOIApplicationsConnectionString %>"
SelectCommand="spBDC_GetAssemblyGroupType" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<ig:WebDataGrid ID="WebDataGrid2" runat="server" Height="350px" Width="400px">
<Behaviors>
<ig:Selection CellClickAction="Row" RowSelectType="Single">
</ig:Selection>
<ig:RowSelectors>
</ig:RowSelectors>
</Behaviors>
</ig:WebDataGrid>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
</form>
</body>
</html>————————————————————————————————————————-
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Infragistics.Web.UI;
using Infragistics.Web.UI.GridControls;
using System;
using System.Configuration;
using System.Collections;
using System.Data;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Fill_AssemblyGroupType_Grid();
}}
protected void Fill_AssemblyGroupType_Grid()
{
string spName = "spBDC_GetAssemblyGroupType";
WebDataGrid.DataManager myDataManager = new WebDataGrid.DataManager("MS_SQL_ConnectionString", "DatabaseType");DataTable myDataTable = new DataTable();
myDataTable = myDataManager.GetDataTableFromSP(spName);WebDataGrid2.DataSource = myDataTable;
WebDataGrid2.DataBind();
WebDataGrid2.Visible = true;
}protected void Button1_Click(object sender, EventArgs e)
{
string tmp;if (WebDataGrid1.Behaviors.Selection.SelectedRows.Count > 0)
{
foreach (GridRecord selectedRow in WebDataGrid1.Behaviors.Selection.SelectedRows) // errors out here with selectedRow returning null
{
tmp = selectedRow.Items.GetValue(1).ToString();
Label1.Text = tmp;}
}}
protected void Button2_Click(object sender, EventArgs e)
{
string tmp;if (WebDataGrid2.Behaviors.Selection.SelectedRows.Count > 0)
{
foreach (GridRecord selectedRow in WebDataGrid2.Behaviors.Selection.SelectedRows) // errors out here with selectedRow returning null
{
tmp = selectedRow.Items.GetValue(1).ToString();
Label2.Text = tmp;}
}}
} -
0
If you're assigning the data source only once the EnableDataViewState
property must be set to True. That way the data will be serialized into
the view state and available after the post back.
Having EnableDataViewState set to False saves tons of view state bytes,
but the data source must be assigned on every post back in that case. -
0
Hello,
Ok It works now.
I loaded data with the SQLDataSource and I can retrieve my selected row fine. It is oK I can have the value of my row selected and put it in session variable.
Could help me for a global problem :
I would like to update my data from my ultrawebgrid to my linqdatasource.
What is the best way to put a submit button.. a special function..
Do you have some example please?
Thank for your help.
-
0
If your linqdatasource supports auto updating both WebDataGrid and
UltraWebGrid will update it automatically.
If you prefer to handle updates manually the WebDataGrid has the
AutoCRUD property off the EditingCore behavior. You can set it to False
and then the grid will only fire updating events without attempting to
update the data source. You can take it from there. UltraWebGrid does
not have this option.
Hope this info helps. -
0
Thank for your anwser.
But When I change the value in my ultrawebgrid, there is no change in the database (SQL).
I would like to have an automatic update without code for this example.
This is the source if you see some anomalies :
Thank in advance for your help.
<%@ Page Language="C#" MasterPageFile="~/MasterPageOc.master" AutoEventWireup="true" CodeFile="Germplasm.aspx.cs" Inherits="Germplasm" Title="Page sans titre" %>
<%
@ Register assembly="Infragistics35.WebUI.UltraWebGrid.v8.3, Version=8.3.20083.1009, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.UltraWebGrid" tagprefix="igtbl" %><%@ Register assembly="Infragistics35.Web.v8.3, Version=8.3.20083.1009, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.GridControls" tagprefix="ig" %>
<
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Browser="Xml"
DataSourceID="LinqDataSource1" Height="200px" Width="325px">
<Bands><igtbl:UltraGridBand AddButtonCaption="inscription" BaseTableName="inscription"
Key="inscription" AllowUpdate="Yes">
<Columns><igtbl:UltraGridColumn BaseColumnName="ins_inscription_sys" IsBound="True"
Key="ins_inscription_sys" AllowUpdate="No">
<Header Caption="ins_inscription_sys">
</Header>
</igtbl:UltraGridColumn><igtbl:UltraGridColumn BaseColumnName="ins_cytopl" IsBound="True"
Key="ins_cytopl" AllowUpdate="Yes">
<Header Caption="ins_cytopl">
<RowLayoutColumnInfo OriginX="1" />
</Header>
<Footer>
<RowLayoutColumnInfo OriginX="1" />
</Footer>
</igtbl:UltraGridColumn>
</Columns>
<AddNewRow View="NotSet" Visible="NotSet">
</AddNewRow>
</igtbl:UltraGridBand>
</Bands><DisplayLayout AllowColSizingDefault="Free" AllowColumnMovingDefault="OnServer"
AllowSortingDefault="OnClient" AllowUpdateDefault="Yes" BorderCollapseDefault="Separate" HeaderClickActionDefault="SortMulti"
LoadOnDemand="Xml" Name="UltraWebGrid1" RowHeightDefault="20px" RowSelectorsDefault="No" SelectTypeRowDefault="Extended"
StationaryMargins="Header" StationaryMarginsOutlookGroupBy="True"
TableLayout="Fixed" Version="4.00"><FrameStyle BackColor="Window" BorderColor="InactiveCaption"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Microsoft Sans Serif"
Font-Size="8.25pt" Height="200px" Width="325px">
</FrameStyle>
<Pager MinimumPagesForDisplay="2">
<PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px"><BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px"
WidthTop="1px" />
</PagerStyle>
</Pager>
<EditCellStyleDefault BorderStyle="None" BorderWidth="0px">
</EditCellStyleDefault>
<FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px"><BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px"
WidthTop="1px" />
</FooterStyleDefault><HeaderStyleDefault BackColor="LightGray" BorderStyle="Solid"
HorizontalAlign="Left"><BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px"
WidthTop="1px" />
</HeaderStyleDefault><RowStyleDefault BackColor="Window" BorderColor="Silver" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt">
<Padding Left="3px" />
<BorderDetails ColorLeft="Window" ColorTop="Window" />
</RowStyleDefault>
<GroupByRowStyleDefault BackColor="Control" BorderColor="Window">
</GroupByRowStyleDefault>
<GroupByBox>
<BoxStyle BackColor="ActiveBorder" BorderColor="Window">
</BoxStyle>
</GroupByBox>
<AddNewBox><BoxStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid"
BorderWidth="1px"><BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px"
WidthTop="1px" />
</BoxStyle>
</AddNewBox>
<ActivationObject BorderColor="" BorderWidth="">
</ActivationObject>
<FilterOptionsDefault><FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid"
BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px" Height="300px"
Width="200px">
<Padding Left="2px" />
</FilterDropDownStyle>
<FilterHighlightRowStyle BackColor="#151C55" ForeColor="White">
</FilterHighlightRowStyle><FilterOperandDropDownStyle BackColor="White" BorderColor="Silver"
BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;"
Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px">
<Padding Left="2px" />
</FilterOperandDropDownStyle>
</FilterOptionsDefault>
</DisplayLayout>
</igtbl:UltraWebGrid><asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataClassesDataContext" Select="new (ins_inscription_sys, ins_cytopl)" TableName="inscription"
EnableUpdate="True">
</asp:LinqDataSource>
</asp:Content>
-
0
I am having an urgent issue with WebDatGrid and retrievng the selected row.
I have a single WDG on my page, and depending on the users' selection from a WebListBar, I redraw the contents of the WDG – using a 32 teir architecture (no direct DB access from the presentation layer)
More specifcally, I create a DataTable and set the WDG.DataSource to it.
I have everything working well for displaying the data… except I cannot get the selected row from the control when I need to.
When the user clicks my "Edit…" button, I *want* to retrieve the selected row, and display a WebDialogWindow with the data to edit…
but this fails everytime…
if
(WebDataGrid1.Behaviors.Selection.SelectedRows.Count > 0) {
foreach (GridRecord row in this.WebDataGrid1.Behaviors.Selection.SelectedRows) {
if (null == row)
_log.Debug(
"SelectedRow is null"); // this always logs!
}
}
Since I am re-assigning DataSource regularly to the WDG, I cannot set EnableDataViewState to True.
This is a showstopper for me – please advise!
-
0
Anyone else having this problem – I found the obvious answer – through talking it through with a colleague –
The WebDataGrid does not have any data in it until I (re)add the datasource to it.
I had previously had
protected void EditButton_Click(object sender, EventArgs e) {
// get selected row
// do stuff…
// generate DataTable and set the WDG datasource;
}
By changing that order, so that I set the WDG datasource FIRST, I have a valid GridRow in SelectedRows.
-
0
Am facing issue in
foreach (GridRecord row in this.availableTasks.Behaviors.Selection.SelectedRows)//in row am getting NULL
{
int wiid = Int32.Parse(row.Items[this.availableTasks.Columns["WorkflowInstanceId"].Index].Value.ToString());
}
EnableDataView property is true for webdatagrid and am binding Data in
Public void PopulateTable()
{
dt =
AvailableTaskManagement.GetAvailableTasksTable(aTasksWfRoles, aTasksQueue, aTasksResultSize, workflowRoles);
if
(updateCounts)
{
//todo: update available tasks count
}
availableTasks.DataSource = dt;
availableTasks.DataBind();
availableTasks.Visible =
true;
}
-
0
My company just brought Infragistics product a few months ago. I encounted the same issue as other people have. I have a webdatagrid and enabled rowselect ='multiple'. However, when I check which rows are selected, the null value is returned from selectedRow. I use dataset as my webdatagrid datasource. What can I do to get the value? I am able to get correct rowselection count.
protected void WebImageButtonAdd_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e) {
string temp = string
.Empty;
if
(CheckBoxCustomer.Checked)
{
InsertNews(Server.HtmlEncode(TextEditorTitle.Text), Server.HtmlEncode(TextEditorDescription.Text),
true, true, WindowsIdentity.GetCurrent().Name, DateTime.Now, WindowsIdentity.GetCurrent().Name, DateTime
.Now);
}
else
{
if
(WebDataGridCustomers.Behaviors.Selection.SelectedRows.Count>0)
{
foreach (GridRecord selectedRow in
WebDataGridCustomers.Behaviors.Selection.SelectedRows)
-
0
This thread might help
http://community.infragistics.com/forums/p/16789/61164.aspx#61164
-
0
Am not binding datasource in source page am binding in server side.and EnableDataViewState is true then also when i select a row its passing null value
foreach (GridRecord r in thi.availableTasks.Behaviors.Selection.SelectedRows)
{
int wiid = Int32.Parse(r.Items[this.availableTasks.Columns["WorkflowInstanceId"].Index].Value.ToString());
}
Please give solution as soon as possible.Its urgent.Thanks in advance
-
-
-
0
this may be a other solution: in WebDataGrid You must set
EnableDataViewState="True" ViewStateMode="Enabled" AND Open selection option
<ig:Selection CellClickAction="Row" RowSelectType="Single" ….>
foreach (Infragistics.Web.UI.GridControls.GridRecord r in WebDataGrid1.Behaviors.Selection.SelectedRows)
{
if (r != null)
{XX = r.Items[WebDataGrid1.Columns["Name"].Index].Value.ToString(); //well be get Cell value or text
}
}
- You must be logged in to reply to this topic.
Suggested Discussions
How to deal with server-side errors in an ajax request?
I’m fairly new using the jQuery controls, so maybe this is obvious, but I’m hoping some…Server-Side Paging in IgxGrid With Total Row Count
Hi all, I’m new in Ignite UI and I’m trying to apply load on demand feature wenn paging…selectedRow returns null
Hi! I’ve been researching a lot to find my problem but didn’t find the solution. I hope…Webdatagrid – How to get value of TemplateDataField – Itemtemplate column value in Javascript client side
Hi, I need to get the cell text value of the Itemtemplate column in javascript. I tried this –…Tags
Created by
Created on
Nov 24, 2017 5:59 AM
Last activity on
Nov 24, 2017 5:59 AM