Hi,
Is there one working example for the captioned event for one gridview as I'm with the following error using the event below. Stackoverflowexception
Thanks. After I've changed the event to be this, I'm still with the following error
protected void gv_ins(object sender, GridViewRowEventArgs e)
{
int tot = gv1.Rows.Count;
for (int r = 0; r < tot; r++)
{
if (gv1.DataKeys[r].Values[1].ToString() == "")
{
gv1.EditIndex = r;
break;
}
}
}
Argumentoutofrangeexception was unhandled by user code
Here is the event
protected void gv_ins(object sender, GridViewRowEventArgs e)
{
int tot = gv1.Rows.Count;
for (int r = 0; r < tot; r++)
{ if (gv1.DataKeys[r].Values[0].ToString() == "") {
gv1.EditIndex = r;
break;
}
}
}
but I'm with this error for line in bold above Argumentoutofrangeexception was unhandled by user code
wmec
Contributor
6219 Points
3217 Posts
Onrowcreated
Oct 12, 2009 02:34 AM|LINK
Hi,
Is there one working example for the captioned event for one gridview as I'm with the following error using the event below.
Stackoverflowexception
protected void gv_ins(object sender, GridViewRowEventArgs e)
{
gv1.DataBind();
}
I do expect to be able to create one new record there
HuaMin Chen
karthicks
All-Star
31374 Points
5420 Posts
Re: Onrowcreated
Oct 12, 2009 03:57 AM|LINK
hi,
why are calling gv1.DataBind(); in row_created event, i think it will end up indefinite recurisve calling of the row_created event,
i.e in row_created event you are calling gv1.DataBind(); that means it will repeatedly call the row_created event without end
Karthick S
sunilyadav16...
Participant
1955 Points
370 Posts
Re: Onrowcreated
Oct 12, 2009 03:59 AM|LINK
Hi,
Seems like your code runs numerous times, and the stack keeps filling up since you are not releasing the resources.
Since your are creating row in one fo the gridview event, can you tell me on which event you are inserting record.
I guess following event gets called numerous times..
protected void gv_ins(object sender, GridViewRowEventArgs e)
{
gv1.DataBind();
}
Follow me here
wmec
Contributor
6219 Points
3217 Posts
Re: Onrowcreated
Oct 12, 2009 04:17 AM|LINK
Thanks. After I've changed the event to be this, I'm still with the following error
protected void gv_ins(object sender, GridViewRowEventArgs e)
{
int tot = gv1.Rows.Count;
for (int r = 0; r < tot; r++)
{
if (gv1.DataKeys[r].Values[1].ToString() == "")
{
gv1.EditIndex = r;
break;
}
}
}
Argumentoutofrangeexception was unhandled by user code
HuaMin Chen
kpyap
Contributor
5212 Points
989 Posts
Re: Onrowcreated
Oct 12, 2009 04:25 AM|LINK
Hi,
Do you have 2 DataKeyNames?
If you only have ONE DataKeyName, then it should be gv1.DataKeys[r].Values[0].ToString()
Index always start from Zero.
Seem like you are trying to do Insert using GridView.
I would suggest place the new inserted row at first row.
Hope it help
karthicks
All-Star
31374 Points
5420 Posts
Re: Onrowcreated
Oct 12, 2009 04:26 AM|LINK
to access datakey value can you try like below
this
.grvManualSchedule.DataKeys[index]["DMPS_FD_Code"].ToString();
and also check the highlighted index
gv1.DataKeys[r].Values[1].ToString()
Karthick S
wmec
Contributor
6219 Points
3217 Posts
Re: Onrowcreated
Oct 12, 2009 04:55 AM|LINK
Sorry for that I've posted something wrongly.
Here is the event
protected void gv_ins(object sender, GridViewRowEventArgs e)
{
int tot = gv1.Rows.Count;
for (int r = 0; r < tot; r++)
{
if (gv1.DataKeys[r].Values[0].ToString() == "")
{
gv1.EditIndex = r;
break;
}
}
}
but I'm with this error for line in bold above
Argumentoutofrangeexception was unhandled by user code
HuaMin Chen
wmec
Contributor
6219 Points
3217 Posts
Re: Onrowcreated
Oct 12, 2009 07:01 AM|LINK
Any advice?
HuaMin Chen
kpyap
Contributor
5212 Points
989 Posts
Re: Onrowcreated
Oct 12, 2009 07:31 AM|LINK
Hi,
Do you set your GridView's DataKeyNames property?
wmec
Contributor
6219 Points
3217 Posts
Re: Onrowcreated
Oct 12, 2009 07:36 AM|LINK
Thanks. How to set that?
HuaMin Chen