Showing posts with label row. Show all posts
Showing posts with label row. Show all posts

Monday, March 26, 2012

populate a dg column based upon the value populated to another row in the datagrid

Is it possible when populating a datagrid to populate a dropdownlist
column based upon the value populated to another row in the datagrid?
(i.e. I have a drop down which I want to populate differently for each
row with user names based upon a UserRegionID which is also a column in
the row).
Since you don't actually know the value of the UserRegionID until the
data is already bound to the datagrid, how do you do this?
Thanks,
Mike
*** Sent via Developersdex http://www.examnotes.net ***You can use the datagrid events (RowDataBound I think) to handle this
by populating your dropdown using the id of each row as the grid is
populated
HTH
---
David Gray
ASP.NET/C# Developer/Architect (MCAD.NET)
On Fri, 13 Jan 2006 02:23:16 -0800, Mike P <mike.parr@.gmail.com>
wrote:

>Is it possible when populating a datagrid to populate a dropdownlist
>column based upon the value populated to another row in the datagrid?
>(i.e. I have a drop down which I want to populate differently for each
>row with user names based upon a UserRegionID which is also a column in
>the row).
>Since you don't actually know the value of the UserRegionID until the
>data is already bound to the datagrid, how do you do this?
>
>Thanks,
>Mike
>
>*** Sent via Developersdex http://www.examnotes.net ***

populate a dg column based upon the value populated to another row in the datagrid

Is it possible when populating a datagrid to populate a dropdownlist
column based upon the value populated to another row in the datagrid?
(i.e. I have a drop down which I want to populate differently for each
row with user names based upon a UserRegionID which is also a column in
the row).

Since you don't actually know the value of the UserRegionID until the
data is already bound to the datagrid, how do you do this?

Thanks,

Mike

*** Sent via Developersdex http://www.developersdex.com ***You can use the datagrid events (RowDataBound I think) to handle this
by populating your dropdown using the id of each row as the grid is
populated

HTH

-------------
David Gray
ASP.NET/C# Developer/Architect (MCAD.NET)

On Fri, 13 Jan 2006 02:23:16 -0800, Mike P <mike.parr@.gmail.com>
wrote:

>Is it possible when populating a datagrid to populate a dropdownlist
>column based upon the value populated to another row in the datagrid?
>(i.e. I have a drop down which I want to populate differently for each
>row with user names based upon a UserRegionID which is also a column in
>the row).
>Since you don't actually know the value of the UserRegionID until the
>data is already bound to the datagrid, how do you do this?
>
>Thanks,
>Mike
>
>*** Sent via Developersdex http://www.developersdex.com ***

Saturday, March 24, 2012

Populate Labels with DataSet in code

I have several Label controls in my page and a stored procedure that always return 1 row. I want to call the same stored procedure with different parameter. Can anybody who me how to do this?

I have a function that contains:

 DataSet objDs =new DataSet();
System.Data.SqlClient.SqlConnection myConnection =new System.Data.SqlClient.SqlConnection(
System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

System.Data.SqlClient.SqlDataAdapter cmd;
cmd =new System.Data.SqlClient.SqlDataAdapter("sp_getCounter1", myConnection);

cmd.SelectCommand.CommandType = CommandType.StoredProcedure;
cmd.SelectCommand.Parameters.Add(
new SqlParameter("@dotnet.itags.org.param1", mode));
DataTable dtMasterListe =new DataTable("mytable");

myConnection.Open();
cmd.Fill(objDs);

With the above code it is easy to e.g bind to datagrid, but I want to achiveve the following Label1.Text = objDs.getstring(etc).

Any clues?

public string FunctionName(){using (SqlConnection cn =new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { SqlCommand cmd =new SqlCommand("StoredProcedureName", cn); cmd.CommandType = CommandType.StoredProcedure;// Add parameters if needed cn.Open();return (string)ExecuteScalar(cmd); }}void Page_Load(){ Label1.Text = FunctionName()}

This is what I usually do:

If you already sure the dataset only contains 1 table and 1 row only, then you can use the following to get the data you want:
Label1.Text = ds.Tables[0].Rows[0][0].ToString();

If you know the table name returned in the dataset, you can also pass in the tablename:
Label1.Text = ds.Tables["tablename"].Rows[0][0].ToString();

It will even be better if you can specify the column name:
Label1.Text = ds.Tables["tablename"].Rows[0]["Name"].ToString();

I usually check if the number of tables & rows > 0 then only get the value:
if ((ds.Tables.Count == 0) && (ds.Tables["tablename"].Rows.Count == 0))

Hope this helps. ^_^



Hi,

If you know that your stored procedure will return only one row all the time, then go for theExcecuteScalar method.


Works perfect!

Had to make a minor change:


int ret = (int)cmd.ExecuteScalar();
return ret.ToString();

to make ExecuteScalar to work.


Thanks.

Populate string array with a SQL row

Can someone tell why I get an "Invalid attempt to read when no data is present. " error?

Here is the code snipplet . . .


SqlCommand DBCommand = new SqlCommand("SELECT * FROM Addresses WHERE AddressID='"+ID.ToString()+"'", DBConn );
try
{
DBConn.Open();
dr = DBCommand.ExecuteReader( System.Data.CommandBehavior.CloseConnection ) ;

}
catch
{
values = null ;
return values ;
}
values[0]=dr["AddressStreet1"].ToString() ;
values[1]=dr["AddressStreet2"].ToString() ;
values[2]=dr["City"].ToString() ;
values[3]=dr["StateProvinceID"].ToString() ;
values[4]=dr["ZipPostalCode"].ToString() ;
values[5]=dr["CountryID"].ToString() ;

Thanks in advance!You need to read the first record of the recordset:

dr.read();
It works except the first column is gone. Why is that?
Disregard my last message - it was my error.

Populate Session Variables from Datagrid for a specific cell

I need to know how to get a specific row/cell of data to post as a session variable - like I would with an ASP.Net table:

Dim ld_sum_tot_cty_tax As Doubl
Session("wa_tot_gal") = tbl_worksheet1.Rows(16).Cells(3).Text(

I am using VB.Net as the code behind, and populating the datagrid dynamically in a VB.Net Class Module - I am NOT connecting to an SQL database, but I do use the databind function

dtg_worksheet1.DataSource = lo_AZRM005A.get_dt_worksheet
dtg_worksheet1.DataBind(

How can I do this programmatically with the datagrid? Any help is GREATLY appreciated! Coleen

--
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/Every row of data which is bound to the grid fires the itemdatabound event.
So in its handler, you can take the appropriate action. Consider
Session["row"] = e.item.cells[0].text will store the first colum of the row
being bou nd

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
<coleenholley> wrote in message
news:%23Nx9N6d6DHA.2568@.TK2MSFTNGP10.phx.gbl...
> I need to know how to get a specific row/cell of data to post as a session
variable - like I would with an ASP.Net table:
> Dim ld_sum_tot_cty_tax As Double
> Session("wa_tot_gal") = tbl_worksheet1.Rows(16).Cells(3).Text()
> I am using VB.Net as the code behind, and populating the datagrid
dynamically in a VB.Net Class Module - I am NOT connecting to an SQL
database, but I do use the databind function:
> dtg_worksheet1.DataSource = lo_AZRM005A.get_dt_worksheet1
> dtg_worksheet1.DataBind()
> How can I do this programmatically with the datagrid? Any help is GREATLY
appreciated! Coleen
> --
> Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest
Community Website: http://www.dotnetjunkies.com/newsgroups/
Thanks - that helps, but I need to get the value from a Specific row - the data returned will ALWAYS have 17 rows - it will return one row for each County in Nevada, and there are 17 Counties. I specifically need to get the value from row (county) 16 for a session variable. Using Session["row"] = e.item.cells[7].text will store the seventh colum of the which row? How do I tell it to specifically get row 16? I REALLY need to have the functionality of Row(16).Cell(7); it is imperitive to the application we are building...any suggestions on getting the exact row number? Thanks for your help. Coleen

--
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
off the top of my head, if i didn't have the dataset already cached, i'd
collect each row and stack it into an array list. Then push that array list
into session.

Remind me again why you need to have this in a session variable (i've lost
the original thread)? It would seem to me that if you cache the entire
dataset, or datatable, then you could easily retrieve the dataset and access
the value directly. Consider:

DataSet ds = Session["Data"] as DataSet;
if(ds != null && ds.Tables[0].Rows.Count > 16)
value = ds.Tables[0].Rows[16][7].ToString();

Ofcourse, it is more memory efficient to cache a datatable or to stack just
the rows in an arraylist.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
<coleenholley> wrote in message
news:uP4atYn6DHA.1040@.TK2MSFTNGP10.phx.gbl...
> Thanks - that helps, but I need to get the value from a Specific row - the
data returned will ALWAYS have 17 rows - it will return one row for each
County in Nevada, and there are 17 Counties. I specifically need to get the
value from row (county) 16 for a session variable. Using Session["row"] =
e.item.cells[7].text will store the seventh colum of the which row? How do
I tell it to specifically get row 16? I REALLY need to have the
functionality of Row(16).Cell(7); it is imperitive to the application we are
building...any suggestions on getting the exact row number? Thanks for your
help. Coleen
> --
> Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest
Community Website: http://www.dotnetjunkies.com/newsgroups/