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

TextBox woes & need help

8 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TIM
Top achievements
Rank 1
TIM asked on 24 Apr 2012, 05:05 PM
Hey Everybody!


I am redoing a clients site from classic asp to asp.net, and all is well up until it came down to a grid.


In short,

The grids columns are dynamic, as the customers site sells clothing, and sizes are dependent on the clothing size.

The grids should contain the contents of:

http://www.logodogzthreadz.com/productdisplay.asp?productID=201 

If you look down below 'Step 1', you'll see the colors name, a preview, and the sizes in columns with textboxes.


So, my question for you is this...


1. How could I add text boxes to a column programatically (in VB)
2. How could I add a color preview? It uses Hex codes, maybe add a label, make it blank and set the backcolor?

A code snippet would be fantastic.

8 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 24 Apr 2012, 06:14 PM
maybe if there is a limited number of sizes then you can declare them all and hide the ones the product doesn't carry
see
http://www.telerik.com/community/forums/aspnet/grid/hide-a-column-in-data-bound-grid-at-run-time.aspx

as for the color - if you make it an image button that selects then on the select event for the item the shirt shown can be replaced with the shirt the same color?

sounds like a challenge
sounds like fun
0
TIM
Top achievements
Rank 1
answered on 24 Apr 2012, 06:30 PM
I realize I could hide a column and such, but how do I add the textbox to the grid row? That is currently where i'm stuck.

Ultimately, I would like to do this programatically.
0
Elliott
Top achievements
Rank 2
answered on 24 Apr 2012, 06:59 PM
my approach is not to add a textbox but to hide unused textboxes
<telerik:GridTemplateColumn UniqueName="XXSmall" HeaderText="XXS" Visible="false">
    <ItemTemplate>
        <asp:TextBox ID="XXSmall" runat="server">
        </asp:TextBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>
and so forth
0
TIM
Top achievements
Rank 1
answered on 24 Apr 2012, 08:47 PM
Awesome, I was able to get the look and such of what I need to do due to your code snippet (I am new to the actual putting stuff into the HTML portion itself, as I normally do it all via code behind).


I am now trying to pull the data from this textbox via a button. I tried doing a grid.FindControl("XXSmall"), however, it returns null. Google search shows various results regarding this, and all of them are stating things like, use it in ItemCreated, or ItemDataBound, or blah blah that's all in the subs of the RadGrid control.

How would I do this from a RadButton instead?
0
Elliott
Top achievements
Rank 2
answered on 24 Apr 2012, 09:01 PM
you need to get the RadAjaxManager set up properly
when the button is pressed it needs to send the grid back to the server
OR
you can build a data table in memory, cache it, then work with that
and grid.FindControl won't cut it
first of all, each textbox is on a row (an item)
so to find a specific amount you first need to iterate through the rows (or work on one row at a time)
then you need to get to a specific TableCell, then within the cell find the textbox
then you can get the value
if your RadAjaxManager is set up correctly you can probably find what you're looking for by casting e.Item to GridDataItem in the ItemDataBound event
0
TIM
Top achievements
Rank 1
answered on 24 Apr 2012, 11:26 PM
I'm sorry but I don't quite understand.


Let me give you what I got so far,

<telerik:RadGrid ID="grid_Colors" runat="server" AutoGenerateColumns="False"
                                    CellSpacing="0" GridLines="None">
 
 
<MasterTableView>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
 
    <Columns>
        <telerik:GridBoundColumn FilterControlAltText="Filter ColorName column"
            HeaderText="Color" UniqueName="ColorName" DataField="ColorName">
        </telerik:GridBoundColumn>
        <telerik:GridTemplateColumn FilterControlAltText="Filter ColorPreview column"
            HeaderText="Preview" UniqueName="ColorPreview" DataField="ColorPreview">
            <ItemTemplate><asp:Label ID="colorPreview_" runat="server" Text="_______" BackColor="#ff66ff"></asp:Label></ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn FilterControlAltText="Filter Size_Small column"
            HeaderText="S" UniqueName="Size_Small" DataField="Size_Small">
            <ItemTemplate>
                <telerik:RadTextBox ID="txt_Small_" runat="server" Width="25" MaxLength="4" Text="0"></telerik:RadTextBox>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn FilterControlAltText="Filter Size_Medium column"
            HeaderText="M" UniqueName="Size_Medium" DataField="Size_Medium">
                       <ItemTemplate>
                <telerik:RadTextBox ID="txt_Medium_" runat="server" Width="25" MaxLength="4" Text="0"></telerik:RadTextBox>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn FilterControlAltText="Filter Size_Large column"
            HeaderText="L" UniqueName="Size_Large" DataField="Size_Large">
                       <ItemTemplate>
                <telerik:RadTextBox ID="txt_Large_" runat="server" Width="25" MaxLength="4" Text="0"></telerik:RadTextBox>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
    </Columns>
 
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
 
<FilterMenu EnableImageSprites="False">
<WebServiceSettings>
<ODataSettings InitialContainerName=""></ODataSettings>
</WebServiceSettings>
                                    </FilterMenu>
 
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
<WebServiceSettings>
<ODataSettings InitialContainerName=""></ODataSettings>
</WebServiceSettings>
</HeaderContextMenu>
                                </telerik:RadGrid>

As you can see I currently have 5 columns, a Bound which will hold the color name, a "preview" which contains a label that I will be able to set the backcolor too, and then 3 "sizes".


Using the following vb code:
Dim test As New DataTable
test.Columns.Add("ColorName")
test.Columns.Add("ColorPreview")
test.Columns.Add("Size_Small")
test.Columns.Add("Size_Medium")
test.Columns.Add("Size_Large")
 
test.Rows.Add("ColorName", "Preview", 1, 2, 3)
test.Rows.Add("ColorName", "Preview", 1, 2, 3)
test.Rows.Add("ColorName", "Preview", 1, 2, 3)
test.Rows.Add("ColorName", "Preview", 1, 2, 3)
test.Rows.Add("ColorName", "Preview", 1, 2, 3)
 
grid_Colors.DataSource = test
grid_Colors.DataBind()


As you can see I am using a datatable. Is it possible to make the itemtemplate pull a variable from the datasource?

For example, I could do: test.Rows.Add("ColorName", "BackColorHexCode", 0, 0, 0)

then, in the LABEL's itemtemplate, set the backcolor to read from the 2nd field?


Also, now, you say to do a radajaxmanager to get the text of the textboxes. How is that even possible? Is there any way to do a for each for each row in the grid then pull values of the fields that way?

I appreciate all the help you've given me, but I apologize that I do not understand.
0
TIM
Top achievements
Rank 1
answered on 25 Apr 2012, 03:40 AM
As per post: http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-get-textbox-control-from-itemtemplate.aspx 

I got the text value to read, HOWEVER, I am running into an issue.

I am using the ajaxproxy(as it's nested), and I set (for testing) button1 to update lbl_Brand.

In my button i have it pull the text, then update lbl_Brand.text with what was pulled. However, it doesn't appear to be ajaxing it as it's doing a postback of some sorts, and then the lbl is showing up the default value of 0. Any ideas?
0
Elliott
Top achievements
Rank 2
answered on 25 Apr 2012, 11:03 AM
I recommend putting in a RadAjaxManager control with the control to update and the updated control set to the grid and see what that clears up

also, if you are going to be adding any javascript, a RadCodeBlock or RadScriptManager

I am only learning this myself
Tags
Grid
Asked by
TIM
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
TIM
Top achievements
Rank 1
Share this question
or