Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET CSS
hi..
 
I want to set position of button and textbox in the same gridview cell at different position in asp.net.i have used gridview control in which, in the gridview header row dynamically buttons and textboxes are generated.i want to set postion of textbox to valign=top and align=center and for button valign=bottom and align=right.provide soln.thanx
Posted 10-Sep-12 23:02pm
Comments
pradiprenushe at 11-Sep-12 5:24am
   
How you are adding it dynamically? Can you show code?
Vijay Walunj,Navi mumbai at 11-Sep-12 5:45am
   
my code is
 
<pre lang="vb">Dim txtFilter As New TextBox

Dim lnkSortCol As New LinkButton</pre>
<pre lang="vb">lnkSortCol.Font.Underline = False

lnkSortCol.CssClass = "headerLnkBtn"
lnkSortCol.Text = ds1.Tables(0).Columns(j).ColumnName
lnkSortCol.ID = "lnkSortCol_" + j.ToString
lnkSortCol.ClientIDMode = UI.ClientIDMode.Static
lnkSortCol.Attributes.Add("onclick", "sort('" + lnkSortCol.ID + "','" + dataType + "');return false;")
grvCtrl.HeaderRow.Cells(0).Controls.AddAt(0, lnkSortCol)

txtFilter.ID = "txtFilter_" + j.ToString
txtFilter.ClientIDMode = UI.ClientIDMode.Static
txtFilter.AutoPostBack = False
txtFilter.ReadOnly = False
txtFilter.CssClass = "txtFilter"
txtFilter.Height = "8"</pre>
grvCtrl.HeaderRow.Cells(0).Controls.AddAt(1, txtFilter)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Rather than adding control individually
add both control in HtmlTable. Add that HtmlTable in gridview.
 
//Create linkbutton & textbox object & assign property here
HtmlTable table1 = new HtmlTable();
            HtmlTableRow row = new HtmlTableRow();
            HtmlTableCell cell;
            for (int j = 1; j <= 2; j++)
            {
                cell = new HtmlTableCell();
                
                if (j == 1)
                {
                    //linkbutton
                    cell.Controls.Add(lnkSortCol );
                    cell.VAlign = "Top";
                }
                else
                {
                    //textbox
                    cell.Controls.Add(txtFilter);
                    cell.VAlign = "Bottom";
                }
                row.Cells.Add(cell);
            }
            grvCtrl.HeaderRow.Cells(0).Controls.AddAt(0, table1);
  Permalink  
v2
Comments
Vijay Walunj,Navi mumbai at 11-Sep-12 8:20am
   
thanku for rply.i want inform you that you miss on line of code
code is
 
table1.Rows.Add(row)
 
Code works
pradiprenushe at 11-Sep-12 8:25am
   
Welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 385
1 BillWoodruff 344
2 George Jonsson 295
3 Sergey Alexandrovich Kryukov 293
4 OriginalGriff 222
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100