RE: GataGrid Command Link Problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Walter -

I think you have this exactly right - Except that I'm working in ASP.NET
2.0. As to Source code, well, I guess I can give you a stripped down version
that's simpler than the real thing and maybe that'll still help you help me!

SAMPLE CODE:
(See comments that start with "//**" below...

protected void Page_Load(object sender, EventArgs e)
{
LoadIssuesDG(m_FilterName, m_SearchStr, m_SortBy);
}

protected void LoadIssuesDG(string FilterName, string SearchStr, string
SortBy)
{
string SQL = BuildQuery(FilterName, SearchStr, SortBy);

OleDbDataReader DR = DB.DoParamSQLGetDataReader(SQL);
if (DR != null)
{
IssuesDG.DataSource = DR;
IssuesDG.DataBind();
}
else
{
ListDescripLB.Text += "<br/>NO ISSUES RETURNED FOR THIS SEARCH.";
}
}


protected void IssuesDG_Sort(Object sender, DataGridSortCommandEventArgs
e)
{
string SortExpression = e.SortExpression.ToString();
LoadIssuesDG(m_FilterName, m_SearchStr, SortExpression);
}



protected void IssuesDG_Command(Object sender, DataGridCommandEventArgs e)
{
string ID = e.Item.Cells[0].Text;
switch (((LinkButton)e.CommandSource).CommandName)
{
case "Edit":
EditItem(ID); //** BEFORE SORT, WORKS FINE. AFTER SORT, ID
IS INCORRECT!
break;

case "View":
ViewItem(ID); //** BEFORE SORT, WORKS FINE. AFTER SORT, ID
IS INCORRECT!
break;

default:
// Do nothing.
break;

}
}

THANKS SO MUCH FOR YOUR HELP!

Alex





"Walter Wang [MSFT]" wrote:

Hi Alex,

Thank you for your post.

Based on my understanding, the question is:
1) You are using DataGrid in ASP.NET 1.1 and it's bound to some data
source;
2) It's set to sortable and you're using the SortCommand to sort it based
on the clicked column's SortExpression, and rebind it after sort.
3) You have some ButtonColumn which are associated with the row index in
the CommandArgument
4) After sort, the ButtonColumn's associate row index is not correct
If I've misunderstood anything, please feel free to post here.

I think the most possible cause of this problem would be: when you rebind
the DataGrid after sorting, the ButtonColumn's associated row index might
not be updated.

If this is not the case or you need more help on this, would you mind
posting some code here so that we can work on it more closely? Thanks.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


.



Relevant Pages

  • dynamic datagrid dropdown valuechanged repopulate 2nd list editmo
    ... I have a dynamic datagrid. ... string strSelectedID; ... I started with creating an ascx control which is a dropdown list. ... public string SelectedValue{ ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Oracle Connection Pooling
    ... > public String oracleFormatUrl(String prefix, String host, String port, ... > proprietaryException { ... > * Map from a resource attribute to a proprietary attribute. ... > protected void processCreateRequests ...
    (comp.lang.java.databases)
  • Re: ParentWert in DataGridColumn anzeigen
    ... > StadtName String 50 ... > StadtID AutoWert ... > OrtsID AutoWert ... Ich fülle das DataGrid selber mit Spalten auf (und ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • Re: problem with IListSource does not contain data source!!
    ... Imports System.Web.UI ... Private strSQLserver As String = "" ... Protected WithEvents grdNames As DataGrid ... Protected Overrides Sub CreateChildControls() ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: Access a class property with a string literal?
    ... > I'm in a weird situation where I'm using ComboBox's in a DataGrid. ... > I want to bind a string to the datagrid, then bind the string and value of a ... When the combobox lookup is changed, ... > the CurrencyManager to get to the bound data and hopefully find the property ...
    (microsoft.public.dotnet.languages.csharp)