Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
pradiprenushe 11-Sep-12 5:24am    
How you are adding it dynamically? Can you show code?
Vijay Walunj,Navi mumbai 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

Rather than adding control individually
add both control in HtmlTable. Add that HtmlTable in gridview.

C#
//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);
 
Share this answer
 
v2
Comments
Vijay Walunj,Navi mumbai 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900