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

Postback on RadGrid row selection

4 Answers 1072 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 11 Aug 2011, 06:02 PM
Hi,
First of all, I am using a RadGrid control from the Q3 2009 package, Windows XP, IE...

I have a page which has a master grid which is linked to another table by datakeynames.  The problem is that this child grid, which works perfectly fine, shares the same space on the web (a table cell actually) with another grid (import grid).  The reason is when a user does something else on the page, this child grid hides and the other appears until the user selects a row on the master again. 

What I find is that if the import grid is visible and I click the master grid, the import grid doesn't hide as the code requests, and the child grid appears, but just as a bunch of text with no datagrid look to it at all.  I find though that if I click a button the postback kicks in properly and suddenly the import grid vanishes and the child table (with the same data as before) appears all nice and pretty.  So, after a lot of testing and research it seems the postback just isn't doing it's job.




This is my table for the child grid and the import grid in my aspx page:



 

<table style="width:100%;">

 

 

<tr>

 

 

<td class="style1" width="50%" align="left" valign="top">

 

 

 

<telerik:RadGrid ID="rgIngredients" runat="server" DataSourceID="odsIngredients"

 

 

AllowPaging="True" GridLines="None" Skin="WebBlue" PageSize="15"

 

 

AutoGenerateColumns="False" >

 

 

 

<PagerStyle Mode="NextPrevNumericAndAdvanced" />

 

 

 

<MasterTableView DataKeyNames="trx-num" CommandItemDisplay="Top" >

 

 

 

<CommandItemTemplate>

 

 

<table width="100%" >

 

 

<tr >

 

 

 

<td style="text-align:center">

 

 

<asp:Label ID="OEHeaderType" Text="Ingredient List"

 

 

runat="server">

 

 

</asp:Label>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</CommandItemTemplate>

 

 

 

<Columns>

 

 

 

<telerik:GridBoundColumn DataField="sequence-no" HeaderText="Seq No." SortExpression="sequence-no"

 

 

UniqueName="sequence-no">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="line-item-type" HeaderText="Type" SortExpression="Type"

 

 

UniqueName="Type">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="product-no" HeaderText="Product No" SortExpression="product-no"

 

 

UniqueName="product-no">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="product-name" HeaderText="Description" SortExpression="product-name"

 

 

UniqueName="product-name">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="crop-yr" HeaderText="Crop Yr" SortExpression="crop-yr"

 

 

UniqueName="crop-yr">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="quantity" HeaderText="Quantity" SortExpression="quantity"

 

 

UniqueName="quantity">

 

 

</telerik:GridBoundColumn>

 

 

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

 

 

<telerik:RadGrid ID="rgImportedItems" runat="server"

 

 

GridLines="None" ShowFooter="false"

 

 

AutoGenerateColumns="false" Skin="Sunset"

 

 

ShowHeader="true" Width="85%" >

 

 

 

<PagerStyle Mode="NextPrevNumericAndAdvanced" />

 

 

 

<MasterTableView CommandItemDisplay="Top" DataKeyNames="Type,ProductCode,Qty,CropYr,UOM,Amount,Account,PCCtr" >

 

 

 

<CommandItemTemplate>

 

 

<table width="100%" >

 

 

<tr >

 

 

 

<td style="text-align:center">

 

 

<asp:Label ID="OEHeaderType" Text="Imported File"

 

 

runat="server">

 

 

</asp:Label>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</CommandItemTemplate>

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="Type" HeaderText="Type">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="ProductCode" HeaderText="Product Code">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Qty" HeaderText="Qty">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="CropYr" HeaderText="Crop Yr">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="UOM" HeaderText="UOM">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Amount" HeaderText="Amount">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Account" HeaderText="Account">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="PCCtr" HeaderText="PCCtr">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

 

 

</td>


And this is what I've tried to do to fix this:

>this executes and nothing on the page changes until I click a button)

 

 

protected void rgCustomFormulas_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

if (e.CommandName == "RowClick")

 

{

rgIngredients.Visible =

true;

 

btnUpload.Text =

"Upload File";

 

lblUpdate.Text =

"";

 

btnPostback_Click(

null, null);

 

}

}

 


>I also tried the __postback javascript thing

 

 

 

function selectAndPostBack() {

 

__doPostBack(

"<%= rgCustomFormulas.UniqueID %>", "RowClicked");

 

}

 

....

 

 

 

protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)

 

{

 

base.RaisePostBackEvent(source, eventArgument);

 

 

if (source == this.rgCustomFormulas && eventArgument.IndexOf("RowClicked") != -1)

 

{

rgImportedItems.Visible =

false;

 

rgIngredients.Visible =

true;

 

btnUpload.Text =

"Upload File";

 

lblUpdate.Text =

"";

 

}

}

So, I've tried a few things.  I am just wondering why clicking a button (which has no code behind, just merely to trigger a postback) corrects the display, and nothing else I've tried so that it's automatic works.  Any suggestions would be appreciated :(

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Aug 2011, 06:07 AM
Hello Randy,

The RowClick event will fire only when you set EnablePostBackOnRowClick property as "true". Also please make sure that you have attached the ItemCommand event.
aspx:
<ClientSettings EnablePostBackOnRowClick="true"
</ClientSettings>

Thanks,
Shinu.
0
Randy
Top achievements
Rank 1
answered on 12 Aug 2011, 03:06 PM

Hi, and thanks for the reply.  I should have posted my whole page, because I actually use EnablePostBackOnRowClick already.  The itemcommand for rowclick fires, I see it with the debug, but it’s just not posting back the way it should I guess (I’m a bit of a newb on the subject).  I wish I could attach files to show you what it’s doing.  It literally seems to queue up those changes that I wanted (hiding a grid, showing another, and changing a button text label) until I force a postback by clicking this go-nowhere button I dropped onto the UI.  It has no code behind it but forces a postback and those queued up changes come into effect and everything is beautiful.  I’m at a loss at the moment.

0
Randy
Top achievements
Rank 1
answered on 12 Aug 2011, 03:08 PM
Here is my master grid, formatted nicer than my last code post.  This is the grid I'm selecting the row on, hoping to have a postback occur.



        <telerik:RadGrid ID="rgCustomFormulas"  runat="server" DataSourceID="odsFormulas"
                AllowPaging="True" GridLines="None" Skin="Forest"
         OnPreRender="rgCustomFormulas_PreRender"  OnItemDataBound="rgCustomFormulas_ItemDataBound"
                OnSelectedIndexChanged="rgCustomFormulas_SelectedIndexChanged" OnItemCommand="rgCustomFormulas_ItemCommand">
               
                <HeaderContextMenu EnableTheming="True" Skin="Office2007">
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                </HeaderContextMenu>
                <PagerStyle Mode="NextPrevNumericAndAdvanced" />
               
                <MasterTableView AutoGenerateColumns="False" DataKeyNames="trx-num, formula-number, warehouse, meas-code, product-no, form-code, default-crop-yr" CommandItemDisplay="Top" >
                    
                    <CommandItemTemplate>
                        <table width="100%" >
                            <tr >
                             
                                    <td style="text-align:center">
                                        <asp:Label ID="OEHeaderType" Text="Custom Formulas"
                                                runat="server">
                                        </asp:Label>
                                    </td>
                            </tr>
                        </table>
                    </CommandItemTemplate>
                       
                    <Columns>
                   
                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Select" Text="Select" ImageUrl="~/images/Zoom16x16.png" HeaderText="Details" UniqueName="select"></telerik:GridButtonColumn>
                           
                        <telerik:GridBoundColumn DataField="formula-number" HeaderText="Formula #" SortExpression="formula-number"
                            UniqueName="formula-number">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="formula-name" HeaderText="Formula Name" SortExpression="formula-name"
                            UniqueName="formula-name">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Cust-no" HeaderText="Customer #" SortExpression="Cust-no"
                            UniqueName="Cust-no">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="warehouse" HeaderText="Warehouse" SortExpression="warehouse"
                            UniqueName="warehouse">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="addr-number" HeaderText="Ship-To Addr" SortExpression="addr-number"
                            UniqueName="addr-number">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="date-changed" HeaderText="Date Chg" DataType="System.DateTime" SortExpression="date-changed"
                            UniqueName="date-changed" DataFormatString="{0:dd/MM/yyyy}">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="effective-date" HeaderText="Eff Date" DataType="System.DateTime" SortExpression="effective-date"
                            UniqueName="effective-date" DataFormatString="{0:dd/MM/yyyy}">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="effective-time" HeaderText="Eff Time" SortExpression="effective-time"
                            UniqueName="effective-time"  >
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="standard-qty" HeaderText="Standard Qty" DataType="System.Decimal" SortExpression="standard-qty"
                             DataFormatString="{0:N4}" UniqueName="standard-qty">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="meas-code" HeaderText="U/M" SortExpression="meas-code"
                            UniqueName="meas-code">
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="product-no" HeaderText="Product #" SortExpression="product-no"
                            UniqueName="product-no" Visible="false">
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="form-code" HeaderText="Form Code" SortExpression="form-code"
                            UniqueName="form-code" Visible="false">
                        </telerik:GridBoundColumn>  
                        <telerik:GridBoundColumn DataField="trx-num" HeaderText="trx-num" SortExpression="trx-num"
                            UniqueName="trx-num" Visible="false">
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="default-crop-yr" HeaderText="Crop Yr" SortExpression="default-crop-yr"
                            UniqueName="default-crop-yr" Visible="false">
                        </telerik:GridBoundColumn> 
                    </Columns>                                             
                   
                </MasterTableView>                  

                <ClientSettings ClientEvents-OnRowClick="selectAndPostBack" EnableRowHoverStyle="True" EnablePostBackOnRowClick="True" AllowColumnsReorder="True">
                    <Selecting AllowRowSelect="True" ></Selecting>
                </ClientSettings>
               
               
               
                <FilterMenu EnableTheming="True" Skin="Office2007">
                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                </FilterMenu>
        </telerik:RadGrid>
           




0
Iana Tsolova
Telerik team
answered on 16 Aug 2011, 11:37 AM
Hi Randy,

Is the page ajaxified? Try disabling temporary ajax and see if it works properly. If yes, then the issue is with the ajax settings. You can post them here for further check.

Furthermore, as EnablePostBackOnRowClick is set to true, you do not need to handle the OnRowClick client-side event.

Additionally, to post your code properly formatted in the forums, you can use the Format Code Block tool of the editor.

Kind regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Randy
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or