Click here to Skip to main content
15,885,985 members

how to fix alignment dynamically textbox in gridview

24983 asked:

Open original thread
Hi,

Thanks in advance,
Im developing in portal I created dynamically four columns in gridview rowdata bound .first column is client,2nd columns in role/position,3rd column in from date -todate (dropdownlist),fourth columns is contnent These are executed when parsing resume.Ineed alignment for these fourcolumns,

C#
protected void WorkExp_Grid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
              if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (e.Row.Cells[0].Text.Length == 0 || e.Row.Cells[0].Text.Equals(" ") || e.Row.Cells[0].Text.Equals("") || e.Row.Cells[0].Text.Equals(string.Empty))
                    {
                        e.Row.Cells[0].Text = string.Empty;
                    }

                    
                    // Start Date
                    string[] startdate = e.Row.Cells[2].Text.Split('/');

                    DropDownList s_m_dl1 = new DropDownList();
                    s_m_dl1.DataSource = monthDataSource();
                    s_m_dl1.DataBind();
                    s_m_dl1.SelectedIndex = Convert.ToInt32(startdate[1]);

                    DropDownList s_y_dl1 = new DropDownList();
                    s_y_dl1.DataSource = yearDataSource();
                    s_y_dl1.DataBind();
                    s_y_dl1.SelectedIndex = Convert.ToInt32(startdate[2]);
                    s_y_dl1.Width = 100;
                    Image mandImg1 = new ImageButton();
                    mandImg1.ImageUrl = "../common/images/Mandatory.gif";

                    e.Row.Cells[2].Controls.Add(mandImg1);
                    e.Row.Cells[2].Controls.Add(s_m_dl1);
                    e.Row.Cells[2].Controls.Add(new LiteralControl("<br><br>  "));
                    e.Row.Cells[2].Controls.Add(s_y_dl1);


                    //Shankar : End Date
                    string[] enddate = e.Row.Cells[3].Text.Split('/');

                    DropDownList e_m_dl1 = new DropDownList();
                    e_m_dl1.DataSource = monthDataSource();
                    e_m_dl1.DataBind();
                    e_m_dl1.SelectedIndex = Convert.ToInt32(enddate[1]);

                    DropDownList e_y_dl1 = new DropDownList();
                    e_y_dl1.DataSource = yearDataSource();
                    e_y_dl1.DataBind();
                    e_y_dl1.SelectedIndex = Convert.ToInt32(enddate[2]);
                    e_y_dl1.Width = 100;
                    Image mandImg2 = new ImageButton();
                    mandImg2.ImageUrl = "../common/images/Mandatory.gif";

                    e.Row.Cells[3].Controls.Add(mandImg2);
                    
                    e.Row.Cells[3].Controls.Add(e_m_dl1);
                    e.Row.Cells[3].Controls.Add(new LiteralControl("<br><br>  "));

                    e.Row.Cells[3].Controls.Add(e_y_dl1);


                    //Shankar : ClientID textbox
                    TextBox txtClientData = new TextBox();
                    txtClientData.Text = e.Row.Cells[0].Text;
                    txtClientData.ID = "clientTXT";

                    AjaxControlToolkit.FilteredTextBoxExtender FtxtClientData = new AjaxControlToolkit.FilteredTextBoxExtender();
                    FtxtClientData.FilterMode = AjaxControlToolkit.FilterModes.InvalidChars;
                    FtxtClientData.InvalidChars = "<>#$%&():+=~`_-|@*~!^?/;\",'\\[]{}";
                    FtxtClientData.TargetControlID = txtClientData.ID;
                    txtClientData.Height = 11;
                    
                    Image mandImg3 = new ImageButton();
                    mandImg3.ImageUrl = "../common/images/Mandatory.gif";

                    Label lblProjNum = new Label();
                    lblProjNum.Text = "Project " + (e.Row.DataItemIndex + 1).ToString();
                    lblProjNum.Attributes.Add("style", "font-weight:bold;font-size:12px");

                    e.Row.Cells[0].Controls.Add(mandImg3);
                    e.Row.Cells[0].Controls.Add(txtClientData);
                    e.Row.Cells[0].Controls.Add(FtxtClientData);
                    e.Row.Cells[0].Controls.Add(new LiteralControl("<br>"));
                    e.Row.Cells[0].Controls.Add(lblProjNum);

                    //Shankar : Position/Role textbox
                    TextBox txtPosRole = new TextBox();
                    if (e.Row.Cells[1].Text.Length == 0 || e.Row.Cells[1].Text.Equals(" ") || e.Row.Cells[1].Text.Equals("") || e.Row.Cells[1].Text.Equals(string.Empty))
                    {
                        //e.Row.Cells[1].Text = " ";
                        e.Row.Cells[1].Text = string.Empty;
                    }
                    txtPosRole.Text = e.Row.Cells[1].Text;
                    txtPosRole.ID = "txtPosRoleID";

                    AjaxControlToolkit.FilteredTextBoxExtender FtxtPosRole = new AjaxControlToolkit.FilteredTextBoxExtender();
                    FtxtPosRole.FilterMode = AjaxControlToolkit.FilterModes.InvalidChars;
                    FtxtPosRole.InvalidChars = "<>#$%&():+=~`_-|@*~!^?/;\",'\\[]{}";
                    FtxtPosRole.TargetControlID = txtPosRole.ID;
                    txtPosRole.Height = 11;

                    e.Row.Cells[1].Controls.Add(txtPosRole);
                    e.Row.Cells[1].Controls.Add(FtxtPosRole);

                    //Shankar : Project content
                    TextBox txtProjDesc = new TextBox();
                    txtProjDesc.ID = "txtProjDescID" + e.Row.RowIndex.ToString();
                    //txtProjDesc.Attributes.Add("onkeypress", "javascript:return fnCheckAlphabets(event);");

                    AjaxControlToolkit.FilteredTextBoxExtender FtxtProjDesc = new AjaxControlToolkit.FilteredTextBoxExtender();
                    FtxtProjDesc.FilterMode = AjaxControlToolkit.FilterModes.InvalidChars;
                    FtxtProjDesc.InvalidChars = "<>$%&()=~`_|@*~!^?/;\"'\\[]{}";
                    FtxtProjDesc.TargetControlID = txtProjDesc.ID;
                    //txtProjDesc.Attributes.Add("onkeypress", "javascript:return fnCheckAlphabets(event);");
                    
                    txtProjDesc.TextMode = TextBoxMode.MultiLine;
                    txtProjDesc.Rows = 10;
                    txtProjDesc.Columns = 30;

                    if (e.Row.Cells[4].Text.Length == 0 || e.Row.Cells[4].Text.Equals(" ") || e.Row.Cells[4].Text.Equals("") || e.Row.Cells[4].Text.Equals(string.Empty))
                    {
                        e.Row.Cells[4].Text = string.Empty;
                    }

                    txtProjDesc.Text = e.Row.Cells[4].Text;
                    txtProjDesc.Text = txtProjDesc.Text.Replace(" ", "");
                    txtProjDesc.Font.Size = FontUnit.Small;
                    e.Row.Cells[4].Controls.Add(txtProjDesc);
                    e.Row.Cells[4].Controls.Add(FtxtProjDesc);

                    //Shankar : Delete Project Button
                    ImageButton imgDelProject = new ImageButton();
                    imgDelProject.Attributes.Add("runat", "server");
                    imgDelProject.CausesValidation = false;
                    //imgDelProject.Attributes.Add("UseSubmitBehavior", "true");
                    //imgDelProject.OnClientClick = "$(this).SuccessBox('Project has been deleted successfully.'); return false;";
                    imgDelProject.OnClientClick = "javascript:collectJSONData(); return ConfirmDeleteProject();";
                    imgDelProject.EnableViewState = true;
                    imgDelProject.ImageUrl = "../common/images/delete.jpg";
                    imgDelProject.ToolTip = "Delete Project";
                    imgDelProject.Command += new System.Web.UI.WebControls.CommandEventHandler(this.DeleteProject);
                    imgDelProject.CommandName = e.Row.DataItemIndex.ToString();
                    e.Row.Cells[5].Controls.Add(imgDelProject);

                }
        }


[edit]code block added[/edit]
Tags: ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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