PDA

View Full Version : [CLOSED] asp.net GridView



gumush75
Apr 02, 2014, 12:28 PM
Hi,

I have a asp.net gridview insider ext container.

After binding data to gridview I call


this.Container6.Render();

so that gridview shows data.

After that, I try to iterate gridview rows by calling directmethod but no rows found.

How can I reach gridview rows ?

Daniil
Apr 02, 2014, 2:05 PM
Hi @gumush75,

Please provide a test case to reproduce.

gumush75
Apr 03, 2014, 6:16 AM
First click "Load Data" button then Save button. If you debug, you will notice that gridview rows are not accessible.

This is aspx part.



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Button runat="server" Text="Load Data" ID="btnLoad" OnDirectClick="btnLoad_DirectClick"></ext:Button>
<ext:Button runat="server" Text="Save" ID="btnSave" OnDirectClick="btnSave_DirectClick"></ext:Button>
<ext:Container runat="server" ID="container6">
<Content>
<asp:GridView runat="server" ID="grd">
<Columns>
<asp:TemplateField HeaderText="TempCol">
<ItemTemplate>
<ext:NumberField runat="server" ID="rnbAmount"></ext:NumberField>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</Content>
</ext:Container>

</div>
</form>
</body>
</html>



And this is .cs part




protected void Page_Load(object sender, EventArgs e)
{

}

/// <summary>
///
/// </summary>
private void BindData()
{
List<object> oList = new List<object>();
oList.Add(new {
Id=1,
Note="Note1"
});

oList.Add(new
{
Id = 2,
Note = "Note2"
});

oList.Add(new
{
Id = 3,
Note = "Note3"
});

this.grd.DataSource = oList;
this.grd.DataBind();

this.container6.Render();
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_DirectClick(object sender, Ext.Net.DirectEventArgs e)
{
int j = 0;
foreach (GridViewRow gr in this.grd.Rows)
{
j++;
}
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnLoad_DirectClick(object sender, Ext.Net.DirectEventArgs e)
{
this.BindData();
}

Daniil
Apr 03, 2014, 2:33 PM
Thanks for the example.

Please try:

<ext:ResourceManager runat="server" DisableViewState="false" />

Ext.NET disables ViewState by default.

gumush75
Apr 03, 2014, 4:24 PM
It does not work :(

I can not reach gridview rows.

Is there any other way to overcome this case ?

Daniil
Apr 03, 2014, 6:31 PM
Please also set up for the ResourceManager

AjaxViewStateMode="Enabled"
or for a specific DirectEvent where you bind the data to the GridView:

<Click OnEvent="btnLoad_DirectClick" ViewStateMode="Enabled">

gumush75
Apr 03, 2014, 7:27 PM
Hi, great, it works.

One more problem. In asp.net gridview I have two template columns with asp.net textbox and ext numberField.

I can not get values from these controls after Save button is clicked. text and number values are null.

Could you check it ? How can I get values ?



<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server" DisableViewState="false" AjaxViewStateMode="Enabled" />
<ext:Button runat="server" Text="Load Data" ID="btnLoad" OnDirectClick="btnLoad_DirectClick" ViewStateMode="Enabled"></ext:Button>
<ext:Button runat="server" Text="Save" ID="btnSave" OnDirectClick="btnSave_DirectClick"></ext:Button>
<ext:Container runat="server" ID="container6">
<Content>
<asp:GridView runat="server" ID="grd">
<Columns>
<asp:TemplateField HeaderText="TempCol1">
<ItemTemplate>
<asp:TextBox runat="server" ID="txt"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TempCol2">
<ItemTemplate>
<ext:NumberField runat="server" ID="rnbAmount"></ext:NumberField>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</Content>
</ext:Container>
</div>
</form>




protected void Page_Load(object sender, EventArgs e)
{

}

/// <summary>
///
/// </summary>
private void BindData()
{
List<object> oList = new List<object>();
oList.Add(new
{
Id = 1,
Note = "Note1"
});

oList.Add(new
{
Id = 2,
Note = "Note2"
});

oList.Add(new
{
Id = 3,
Note = "Note3"
});

this.grd.DataSource = oList;
this.grd.DataBind();

this.container6.Render();
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_DirectClick(object sender, Ext.Net.DirectEventArgs e)
{
int j = 0;
foreach (GridViewRow gr in this.grd.Rows)
{
NumberField r = (NumberField)gr.FindControl("rnbAmount");
TextBox t = (TextBox)gr.FindControl("txt");
string text = t.Text;
double number = r.Number;
}
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnLoad_DirectClick(object sender, Ext.Net.DirectEventArgs e)
{
this.BindData();
}

Daniil
Apr 04, 2014, 4:00 AM
Please apply the following changes:

1. Remove:

this.grd.DataBind();

2. Add this handler for the GridView.

OnRowCreated="grd_RowCreated"

int index = 0;

protected void grd_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.ID = "_Row" + ++index;
}

P.S. There is a possibility that other issues pop up, so, we would suggest to consider to move to an Ext.NET GridPanel control.

gumush75
Apr 04, 2014, 4:50 AM
I will try it.