This is a migrated thread and some comments may be shown as answers.

GridButtonColumn Index Invalid

3 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 27 Dec 2011, 06:39 AM
I have two different grids on two different pages (one grid per page).
Both grids have been populated with data containing a single row.
Both grids have a GridButtonColumn for requesting processing against the data row.
Both grids are defined nearly exactly (except for data column names, etc.)
Both grids have a "_ItemCommand" in the code behind file for processing the buttons/data.
Both grids contain exactly the same code in the code behind file (except for the column name they are handling/examining).

The first grid functions perfectly and the button performs as advertised.

The second grid will not process correctly.  It blows up with a "" error.  It does see the button event. It does trigger the intended event code.

The code behind event code is:

protected void QualContsGrid_ItemCommand(Object source, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == "RemoveContribution")
    {
        //  First we need to get the key value of the record the user wants to remove from the list
        string code = (string)e.CommandArgument;
        string id = (e.Item as GridDataItem).GetDataKeyValue("VoterQualifyingContributionId").ToString();
        Int32 iContributorRecKey = Convert.ToInt32(id);
 
        //  Now we can get the record, change it (remove it from the list), and update it
        ElectronicPetitionSystemDataContext efdc = new ElectronicPetitionSystemDataContext(ConfigurationManager.ConnectionStrings["ElectronicPetitionSystemConnectionString"].ConnectionString);
        VoterQualifyingContribution qc = efdc.VoterQualifyingContributions.Single(qcrec => qcrec.VoterQualifyingContributionId == iContributorRecKey);
        string sFirst = qc.FirstName;
        string sLast = qc.LastName;
        qc.VoterQualifyingContributionStatusId = 2;
        efdc.SubmitChanges();
        this.QualContsGrid.Rebind();
    }
}

The grid definition code is:

<telerik:RadGrid AutoGenerateColumns="false" ID="QualContsGrid" runat="server" Width="765px" OnItemCommand="QualContsGrid_ItemCommand"
    Height="430px"
    AllowSorting="true" AllowFilteringByColumn="true" EnableLinqExpressions="true"
    OnItemDataBound="QualContsGrid_ItemDataBound"
    AllowPaging="true" PageSize="15"
    BorderWidth="1px" BorderColor="#999999" EnableEmbeddedSkins="true" Skin="Default"
    DataSourceID="SQLDataSource1"
    ShowFooter="True" GridLines="None" >
    <StatusBarSettings ReadyText="Ready" LoadingText="Loading..." />
    <MasterTableView >
        <Columns>
            <telerik:GridBoundColumn HeaderStyle-Width="100px" UniqueName="VoterFirstName" HeaderText="First Name" DataField="FirstName" SortExpression="FirstName" >
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderStyle-Width="100px" UniqueName="VoterLastName" HeaderText="Last Name" DataField="LastName" SortExpression="LastName" >
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderStyle-Width="300px" UniqueName="VoterAddress" HeaderText="Address" DataField="Address" SortExpression="Address" >
            </telerik:GridBoundColumn >
            <telerik:GridButtonColumn DataTextFormatString="Remove" ButtonType="PushButton" UniqueName="RemoveContribution" HeaderStyle-Width="75px"
                ConfirmText="Are you certain that you want to remove this contribution?"  Text="Remove"
                HeaderText="Remove" CommandName="RemoveContribution" CommandArgument="VoterQualifyingContributionId" DataTextField="VoterQualifyingContributionId" >
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn HeaderStyle-Width="100px" UniqueName="ContributionStatus" HeaderText="Status" DataField="PaymentDescription" SortExpression="PaymentDescription" >
            </telerik:GridBoundColumn >
            <telerik:GridBoundColumn UniqueName="VoterQualifyingContributionId" HeaderText="" DataField="VoterQualifyingContributionId" Visible="false" >
            </telerik:GridBoundColumn >
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    </ClientSettings>
</telerik:RadGrid>

I have also attached two screen captures.

Many thanks in advance for any assistance you can give me!

Lynn



3 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Dec 2011, 09:01 AM
Hello,

<MasterTableView  DataKeyNames="VoterQualifyingContributionId" >

or

string VoterQualifyingContributionId = e.CommandArgument.toString();


Thanks,
Jayesh Goyani
0
Lynn
Top achievements
Rank 2
answered on 27 Dec 2011, 03:21 PM
Jayesh,

Thank you for the response and the assist!  For some reason, I didn't receive an email about your submittal and had just found a different solution per the code below when I checked and found your response:
GridDataItem item = (GridDataItem)e.Item;
string str = item["VoterQualifyingContributionId"].Text;

Your solution is most interesting as well!

Thanks again!

Lynn
0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Dec 2011, 06:20 PM
Hello,

if you not get the mail from this forum then please check the "Subscribe me for this thread".

which was below the attach your files.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Lynn
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Lynn
Top achievements
Rank 2
Share this question
or