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

[Solved] Row Click value assign in new textbox

12 Answers 302 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mohamed
Top achievements
Rank 1
mohamed asked on 30 Apr 2011, 06:49 AM
which row i click that row name go to top of second asp:textbox




using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.Data.SqlClient;
using System.Configuration;
using TBSDataLayer;

namespace TBS_HelpDesk.Views.Assets
{
    public partial class NewModels : System.Web.UI.Page
    {
        public static string Manuf_ID;
        private SqlDataAdapter sqladp;
        private SqlCommand sqlcmd;
        private DataTable dtTable;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Manuf_ID = "0";
            }
        }

        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            AssetModel oAssetModel = new AssetModel();
            RadGrid1.DataSource = oAssetModel.fetchAssetManufacturer();
        }

        protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            AssetModel oAssetModel = new AssetModel();
            RadGrid2.DataSource = oAssetModel.fetchAssetModel(Manuf_ID);
        }

        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            dtTable = new DataTable();
            sqladp = new SqlDataAdapter();
            sqlcmd = new SqlCommand();
            Manufacturers oManufacturers = new Manufacturers();

            if (e.CommandName == RadGrid.PerformInsertCommandName)
            {

                if (e.Item is GridEditFormItem)
                {
                    GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;
                    TextBox Manuf_Name = (e.Item as GridEditFormInsertItem)["Manuf_Name"].Controls[0] as TextBox;
                    TextBox Manuf_Description = (e.Item as GridEditFormInsertItem)["Manuf_Description"].Controls[0] as TextBox;
                    CheckBox Manuf_Inactive = (e.Item as GridEditFormInsertItem)["Manuf_Inactive"].Controls[0] as CheckBox;

                    //GridEditFormItem item = (GridEditFormItem)e.Item;
                    //TextBox Manuf_Name = (TextBox)item.FindControl("Manuf_Name");
                    //TextBox Manuf_Description = (TextBox)item.FindControl("Manuf_Description");
                    //CheckBox Manuf_Inactive = (CheckBox)item.FindControl("Manuf_Inactive");
                    // newly changed

                    oManufacturers.Manuf_Name = Manuf_Name.Text;
                    oManufacturers.Manuf_Description = Manuf_Description.Text;
                    oManufacturers.Manuf_Inactive = Manuf_Inactive.Checked;

                    try
                    {
                        RadGrid1.DataSource = oManufacturers.AddManufacturers(oManufacturers.Manuf_Name, oManufacturers.Manuf_Description, oManufacturers.Manuf_Inactive);
                    }
                    catch (Exception ex)
                    {
                        RadGrid1.Controls.Add(new LiteralControl("Unable to insert Employee. Reason: " + ex.Message));
                    }
                    RadGrid1.MasterTableView.IsItemInserted = false;
                    RadGrid1.DataBind();
                    e.Canceled = true;
                }
                //GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;
                //TextBox Manuf_Name = (e.Item as GridEditFormInsertItem)["Manuf_Name"].Controls[0] as TextBox;
                //TextBox Manuf_Description = (e.Item as GridEditFormInsertItem)["Manuf_Description"].Controls[0] as TextBox;
                //CheckBox Manuf_Inactive = (e.Item as GridEditFormInsertItem)["Manuf_Inactive"].Controls[0] as CheckBox;

            }
            else if (e.CommandName == RadGrid.UpdateCommandName)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;

                if (e.Item is GridEditFormItem)
                {
                    GridEditFormItem item = (GridEditFormItem)e.Item;
                    TextBox Manuf_ID = (e.Item as GridEditableItem)["Manuf_ID"].Controls[0] as TextBox;
                    TextBox Manuf_Name = (e.Item as GridEditableItem)["Manuf_Name"].Controls[0] as TextBox;
                    TextBox Manuf_Description = (e.Item as GridEditableItem)["Manuf_Description"].Controls[0] as TextBox;
                    CheckBox Manuf_Inactive = (e.Item as GridEditableItem)["Manuf_Inactive"].Controls[0] as CheckBox;

                    //GridEditFormItem item = (GridEditFormItem)e.Item;
                    //TextBox Manuf_ID = (TextBox)item.FindControl("Manuf_ID");
                    //TextBox Manuf_Name = (TextBox)item.FindControl("Manuf_Name");
                    //TextBox Manuf_Description = (TextBox)item.FindControl("Manuf_Description");
                    //CheckBox Manuf_Inactive = (CheckBox)item.FindControl("Manuf_Inactive");

                    oManufacturers.Manuf_ID = Convert.ToInt32(Manuf_ID.Text);
                    oManufacturers.Manuf_Name = Manuf_Name.Text;
                    oManufacturers.Manuf_Description = Manuf_Description.Text;
                    oManufacturers.Manuf_Inactive = Manuf_Inactive.Checked;

                    try
                    {
                        RadGrid1.DataSource = oManufacturers.ModManufacturers(oManufacturers.Manuf_ID, oManufacturers.Manuf_Name, oManufacturers.Manuf_Description, oManufacturers.Manuf_Inactive);
                    }
                    catch (Exception ex)
                    {
                        RadGrid1.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));

                    }
                    RadGrid1.EditIndexes.Clear();
                    RadGrid1.DataBind();
                    e.Canceled = true;

                }
                //RadNumericTextBox Manuf_ID = (e.Item as GridEditableItem)["Manuf_ID"].Controls[0] as RadNumericTextBox;
                //TextBox Manuf_Name = (e.Item as GridEditableItem)["Manuf_Name"].Controls[0] as TextBox;
                //TextBox Manuf_Description = (e.Item as GridEditableItem)["Manuf_Description"].Controls[0] as TextBox;
                //CheckBox Manuf_Inactive = (e.Item as GridEditableItem)["Manuf_Inactive"].Controls[0] as CheckBox;


            }
            else if (e.CommandName == RadGrid.DeleteCommandName)
            {
                GridDataItem item = (GridDataItem)e.Item;
                Int32 Manuf_ID = Convert.ToInt32(item["Manuf_ID"].Text);

                try
                {
                    RadGrid1.DataSource = oManufacturers.DelManufacturers(Manuf_ID);

                }
                catch (Exception ex)
                {
                    RadGrid1.Controls.Add(new LiteralControl("Unable to delete Id. Reason: " + ex.Message));
                    e.Canceled = true;
                }

            }
            else if (e.CommandName == "RowClick")
            {
                GridDataItem item = (GridDataItem)e.Item;
                Manuf_ID = item["Manuf_ID"].Text;
                string Manuf_Name = item["Manuf_Name"].Text;
                ModelText.Text = "Model For " + item["Manuf_Name"].Text;
                RadGrid2.DataSource = null;
                RadGrid2.Rebind();
                ModelText.Text = "Model For " + Manuf_Name;
                //e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;
            }
        }

        protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
        {

            dtTable = new DataTable();
            sqladp = new SqlDataAdapter();
            sqlcmd = new SqlCommand();
            AssetModel oAssetModel = new AssetModel();

            if (e.CommandName == RadGrid.PerformInsertCommandName)
            {
                GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;

                RadNumericTextBox Model_ID = (e.Item as GridEditFormInsertItem)["Model_ID"].Controls[0] as RadNumericTextBox;
                TextBox Model_Name = (e.Item as GridEditFormInsertItem)["Model_Name"].Controls[0] as TextBox;
                TextBox Model_Description = (e.Item as GridEditFormInsertItem)["Model_Description"].Controls[0] as TextBox;
                oAssetModel.Model_Manuf_ID = Convert.ToInt16(Manuf_ID);
                oAssetModel.Model_Name = Model_Name.Text;
                oAssetModel.Model_Description = Model_Description.Text;

                try
                {
                    RadGrid2.DataSource = oAssetModel.AddAssetModel(oAssetModel.Model_Manuf_ID, oAssetModel.Model_Name, oAssetModel.Model_Description);
                }
                catch (Exception ex)
                {
                    RadGrid2.Controls.Add(new LiteralControl("Unable to insert Employee. Reason: " + ex.Message));
                }
                RadGrid2.MasterTableView.IsItemInserted = false;
                RadGrid2.DataBind();
                e.Canceled = true;
            }

            else if (e.CommandName == RadGrid.UpdateCommandName)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;

                RadNumericTextBox Model_ID = (e.Item as GridEditableItem)["Model_ID"].Controls[0] as RadNumericTextBox;
                TextBox Model_Name = (e.Item as GridEditableItem)["Model_Name"].Controls[0] as TextBox;
                TextBox Model_Description = (e.Item as GridEditableItem)["Model_Description"].Controls[0] as TextBox;

                oAssetModel.Model_Manuf_ID = Convert.ToInt16(Manuf_ID);
                oAssetModel.Model_ID = Convert.ToInt16(Model_ID.Text);
                oAssetModel.Model_Name = Model_Name.Text;
                oAssetModel.Model_Description = Model_Description.Text;

                try
                {
                    RadGrid2.DataSource = oAssetModel.ModAssetModel(oAssetModel.Model_Manuf_ID, oAssetModel.Model_ID, oAssetModel.Model_Name, oAssetModel.Model_Description);
                }
                catch (Exception ex)
                {
                    RadGrid2.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));

                }
                RadGrid2.EditIndexes.Clear();
                RadGrid2.DataBind();
                e.Canceled = true;

            }

            else if (e.CommandName == RadGrid.DeleteCommandName)
            {

                GridDataItem item = (GridDataItem)e.Item;
                oAssetModel.Model_Manuf_ID = Convert.ToInt16(Manuf_ID);
                Int32 Model_ID = Convert.ToInt16(item["Model_ID"].Text);


                try
                {
                    RadGrid2.DataSource = oAssetModel.DelAssetModel(oAssetModel.Model_Manuf_ID, Model_ID);
                }
                catch (Exception ex)
                {
                    RadGrid2.Controls.Add(new LiteralControl("Unable to delete Id. Reason: " + ex.Message));
                    e.Canceled = true;
                }

            }
        }

        protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
        {

        }
        protected void RadToolBar2_ButtonClick(object sender, RadToolBarEventArgs e)
        {

        }

    }
}



Thanks
Mohamed

12 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Apr 2011, 07:49 AM
Hello Mohamed,

I am not quite sure about your requirement. I suppose you a RagGrid and a TextBox out side the Grid and you want to set the TextBox value with a particular cell value when clicking the row.

If that is the requirement attach the ClientEvent OnRowClick and set the TextBox value. Here is a sample code.

Javascrpt:
<script type="text/javascript">
    function OnRowClick(sender, args)
    {
        var txtBox = document.getElementById("TextBox1");
        txtBox .innerText = args.get_gridDataItem().get_cell("ColumUniqueName").innerText
    }
</script>

Please elaborate your scenario i f it doesn't help.

Thanks,
Princy.
0
mohamed
Top achievements
Rank 1
answered on 30 Apr 2011, 08:04 AM
Thanks For Ur Princy,


If We possible call at server side like that


and one more doubt selected row how we give color

else if (e.CommandName == "RowClick")
            {
                GridDataItem item = (GridDataItem)e.Item;
                Manuf_ID = item["Manuf_ID"].Text;
                string Manuf_Name = item["Manuf_Name"].Text;
                ModelText.Text = "Model For " + item["Manuf_Name"].Text;
                RadGrid2.DataSource = null;
                RadGrid2.Rebind();
                ModelText.Text = "Model For " + Manuf_Name;
                //e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;
            }

Thanks
Mohamed
0
Princy
Top achievements
Rank 2
answered on 02 May 2011, 06:09 AM
Hello Mohamed,

Try the following code snippet. Hope this helps you.

C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
   {
       if (e.CommandName == "RowClick")
       {
           (e.Item as GridDataItem).BackColor = System.Drawing.Color.Red;
       }
   }

Note: Set EnablePostBackOnRowClick as true.

Thanks,
Princy.
0
mohamed
Top achievements
Rank 1
answered on 02 May 2011, 07:19 AM
Thanks for ur reply Princy

if we possible give like that
how to coordinate  in java script

How I bold innertext value

function OnRowClick(sender, args) {
                debugger;
                var ModelText = document.getElementById("MainContent_ModelText");
                var model = "Model for";
                 model + ModelText.innerText = args.get_gridDataItem().get_cell("Manuf_Name").innerText
            }

Back Color come after i click another row that color not disappear

Thanks,
Mohamed
0
Shinu
Top achievements
Rank 2
answered on 02 May 2011, 11:51 AM
Hello,

You can do this by trying the following code snippet. Hope this helps you.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "RowClick")
  {
    foreach(GridDataItem item in RadGrid1.MasterTableView.Items)
    {
      GridDataItem newItem = (GridDataItem)e.Item;
      item.BackColor = System.Drawing.Color.Empty;
    }
  (e.Item as GridDataItem).BackColor = System.Drawing.Color.Red;
  }
}

Thanks,
Shinu
0
mohamed
Top achievements
Rank 1
answered on 02 May 2011, 12:04 PM
Hello Shinu,
Thanks  for your reply.

how to coordinate  in java script

How I bold innertext value

function OnRowClick(sender, args) {
                debugger;
                var ModelText = document.getElementById("MainContent_ModelText");
                var model = "Model for";
                 model + ModelText.innerText = args.get_gridDataItem().get_cell("Manuf_Name").innerText
            }

Thanks,
Mohamed
0
Shinu
Top achievements
Rank 2
answered on 02 May 2011, 01:12 PM
Hello Mohamed,

Try the following client code:
Javascript:
function OnRowClick(sender, args)
    {
        args.get_gridDataItem().get_cell("FirstName").style.fontWeight = "bold";
    }

Thanks,
Shinu.
0
mohamed
Top achievements
Rank 1
answered on 02 May 2011, 01:36 PM
Thanks Shinu,

i'm going to bold in label value nor grid value .
Important thing i need't
i got result is "hp"
i'm going show like that "Model For Hp" in that label
how i do

function OnRowClick(sender, args) {
                debugger;
                var ModelText = document.getElementById("MainContent_ModelText");
                ModelText.innerText = args.get_gridDataItem().get_cell("Manuf_Name").innerText 
             
            }


Thanks,
Mohamed
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 May 2011, 06:59 AM
Hello Mohamed,

You could apply the style as follows
javascript:
 var label = document.getElementById("Label1");
 label.style.fontWeight = "Bold"

Thanks,
Shinu.
0
mohamed
Top achievements
Rank 1
answered on 03 May 2011, 07:49 AM
Hi  Shinu,

Thanks For Ur reply
Bold working fine .
but my main issue is coordination

i want coordinate two values in one asp lable is't possible
in that script

function OnRowClick(sender, args) {
                debugger;
                var ModelText = document.getElementById("MainContent_ModelText");
                ModelText.innerText = args.get_gridDataItem().get_cell("Manuf_Name").innerText 
             
            }

Thanks ,
Mohamed
0
Accepted
Shinu
Top achievements
Rank 2
answered on 04 May 2011, 08:46 AM
Hello Mohamed,

Try the following code.
javascript:
<script type="text/javascript">
    function OnRowClick(sender, args)
    {
        var label = document.getElementById("Label1");
        var lbltxt = label.innerText;
        lbltxt += args.get_gridDataItem().get_cell("FirstName").innerText;
        label.innerText = lbltxt;
    }
</script>

Thanks,
Shinu.
0
mohamed
Top achievements
Rank 1
answered on 04 May 2011, 11:01 AM
Thanks a lot Shinu nice work

Thanks,
Mohamed
Tags
Grid
Asked by
mohamed
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
mohamed
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or