views:

250

answers:

2

I have a Telerik's RadGrid which has 2 columns like this:

<Columns>
 <telerik:GridBoundColumn HeaderText="AirlineCode" UniqueName="AirlineCode" DataField="airlineCode" />
 <telerik:GridBoundColumn HeaderText="FlightNumber " EditFormColumnIndex="1" DataField="flightNumber" />
 ... 
 ... 
 ... more code, but unrelevant to the question here.
</Columns>

I am supplying the data for both columns in the relevant NeedDataSource() function.

So it renders correctly like this:

 | AirlineCode      |      FlightNumber   | 
 ------------------------------------------
 | Delta            |      2393           | 
 | Southwest        |      345            | 

But now my requirement has changed a little bit.

For viewing, I want to merge them together and show it like this:

 |     Flight             |
 --------------------------
 |     Delta-2393         | 
 |     Southwest-345      | 

However, while editing the rows the user should be able to edit "AirlineCode" and "Flight Number" separately. And the values should still be correctly maintained in the datasource.

I know that if we want the user to "View" and "Edit" differently, we would have to use .

So I am trying something like this:

<Columns>
 <telerik:GridTemplateColumn EditFormColumnIndex="0" HeaderText="Flight">
   <ItemTemplate>
  <%#DataBinder.Eval(Container.DataItem, "airlineCode")%>
  <asp:Literal runat="server" Text="-"></asp:Literal>
  <%#DataBinder.Eval(Container.DataItem, "flightNumber")%>
   </ItemTemplate>
   <EditItemTemplate>
  <telerik:GridBoundColumn HeaderText="AirlineCode" UniqueName="AirlineCode" DataField="airlineCode" />
  <telerik:GridBoundColumn HeaderText="FlightNumber " EditFormColumnIndex="1" DataField="flightNumber" />
   </EditItemTemplate>
 </telerik:GridTemplateColumn> ... 
 ... 
 ... more code, but unrelevant to the question here.
</Columns>

But its not working.

Those 2 lines inside are giving warnings:

Element 'GridBoundColumn' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.

Probably I am doing it wrong. Need help.

Any help is appreciated.

A: 

It has been a while since I used the radgrid, but in your edit template I believe you need to remove the GridBoundColumns and put two textbox controls separated by the dash. Then use your Databinder to fill those txt boxes. Sorry I can't be more concise as I'm typing on my iPhone and can't test. I will followup with you when I am in front of my machine.

Good luck!

drpcken
I thought of using text boxes as you suggested. But I wasn't sure about how to use the databinder part you just mentioned. I want the rest of the code (especially in NeedDataSource()) to remain the same.Thanks for following up whenever possible.
noops
You'll need to use the Databinder.Bind instead of Databinder.Eval for binding to text boxes and grabbing the values to pass to a data access layer or method. Instead of using a two GridBoundColumns, use a single GridTemplateColumn with two TextBoxes for the EditItemTemplate. For the TextBoxes.Text properties of the txtboxes, use <pre><code><% #DataBinder.Bind(DataItem.Container("airlineCode") %> - <% #DataBinder.Bind(DataItem.Container("flightNumber") %> </code></pre>
drpcken
Sorry I'm having issues figuring out how to markup the code. New to the site too :)
drpcken
Sorry I followed up late. I ended up using RadTextBox later on as you advised and it worked for me. Thanks.
noops
No problem. Glad I could help and glad you got it working! Thanks!
drpcken
A: 

drpcken is correct. When you use the GridTemplateColumn, you do not need to use the GridBoundColumn. Instead, you supply the View and Edit template HTML and use the Bind expression to do two-way binding in the Edit template. For example:

<telerik:GridTemplateColumn UniqueName="TemplateColumn">                          
         <ItemTemplate>
              <%# Eval("airlinCode") %> - <%# Eval("flightNumber") %>
          </ItemTemplate>
          <EditItemTemplate>
              <table>
                 <tr>
                   <td style="width: 50%">
                     <asp:TextBox runat="server" Text='<%# Bind("airlineCode") %>' />
                   </td>
                   <td style="width: 50%">
                      <asp:TextBox runat="server" Text='<%# Bind("flightNumber") %>' />
                   </td>
                  </tr>
               </table>
          </EditItemTemplate>
</telerik:GridTemplateColumn>

As you can see, you use Eval in the ItemTemplate and Bind in the EditItemTemplate. All other code should continue to work without change.

Let me also highlight the Telerik Forums. For Telerik specific questions, there is an active community available to help troubleshoot: www.telerik.com/forums

Todd