المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Pass variable from GridViewRowEvent method to DataListItemEvent method in C# using ASP.NET



C# Programming
04-05-2010, 09:11 PM
I'm trying to pass a variable from a GridViewRowEvent method to a DataListItemEvent method in a C# program.

I have the following:

public void My_RowDataBound2(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int lblAmount = (int)DataBinder.Eval(e.Row.DataItem, "Amount");
totalAmount += lblAmount;
x += 1;
}
else {
CountNumberRows(x);
}
}

public int CountNumberRows(int x) { return x; }

public void My_ItemDataBound(object sender, DataListItemEventArgs e) {
if (e.Item.DataItem != null)
{
Label dummyVariable = (Label)e.Item.FindControl("abc");
abc.Text = CountNumberRows(x).ToString();
}
}
Then in my ASP.NET file I have the following entry:

DataList
...
Gridview
...
Gridview
...
<span class="code-keyword">...
DataList

And I get just "0" for the "abc" value in my file. I know the GridViewEvent method works because the variable totalAmount correctly sums up all the data each time it is called by My_RowDataBound2, and inserted into the appropriate place in the GridView on my ASP.NET Page. But "abc" just shows 0. abc is just supposed to show the number of rows contained in the GridView.

Basically, I just need to get the "x" value from My_RowDataBound2 method, pass it to the My_ItemDataBound event which then passes it as a label to the ASP.NET Page. But the label is just showing "0"


If I take: public int CountNumberRows(int x) { return x; } and change it to: public int CountNumberRows(int x) { x= "123"; return x; } , it passes the "123" to the abc label. But I don't know how to pass the x calculation out of the GridView to the DataList. Any suggestions? I appreciate your help