473,480 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Bind a selected value from dropdownlist to gridview(urgent)

9 New Member
Hi friends..
Im trying to bind a value from dropdownlist placed in gird view to another cell. i want to update a database field with the selected value from dropdownlist and which must be bind to gridview... please help me .. im using sql server2000 as datasource..

public partial class Propertydetails : System.Web.UI.Page
{
protected static string connect;
string ct, struName;
protected void Page_Load(object sender, EventArgs e)
{
string username = Session["UserName"].ToString();
connect = System.Configuration.ConfigurationManager.AppSetti ngs["connect"];
SqlConnection con = new SqlConnection();
con.ConnectionString = connect;
con.Open();

string s = "select PM.RegisterID,PM.PropertyID,PR.PropertyName,CD.Cat egoryName from PropertyMember PM,Property PR,CategoryDetails CD where PM.UserName='" + username + "'and PM.PropertyID=PR.PropertyID and CD.CategoryType=PM.CategoryType";
SqlDataSource1.ConnectionString = connect;
SqlDataSource1.SelectCommand = s;
con.Close();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
// DropDownList ddl1 = new DropDownList();
// //ddl1 = (DropDownList)GridView1.SelectedRow.FindControl("D ropDownList1");
// cname = ddl1.SelectedValue.ToString();
// Session["cname1"] = cname;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string username = Session["UserName"].ToString();
SqlConnection con = new SqlConnection(connect);

string select = "Select CategoryType from CategoryDetails where CategoryName='" + struName + "'";
SqlDataReader dr = null;
SqlCommand cmd1 = new SqlCommand(select, con);
con.Open();
dr = cmd1.ExecuteReader();
while (dr.Read())
{
struName = dr[0].ToString();
}

struName = ((DropDownList)((GridView)sender).Rows[e.RowIndex].FindControl("DropDownList1")).SelectedValue;
e.NewValues["CategoryName"] = struName;
e.Cancel = false;
con.Close();
}
}



please help me..
thanks for all kind of support
Feb 9 '08 #1
1 3002
nateraaaa
663 Recognized Expert Contributor
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string username = Session["UserName"].ToString();
SqlConnection con = new SqlConnection(connect);

string select = "Select CategoryType from CategoryDetails where CategoryName='" + struName + "'";
SqlDataReader dr = null;
SqlCommand cmd1 = new SqlCommand(select, con);
con.Open();
dr = cmd1.ExecuteReader();
while (dr.Read())
{
struName = dr[0].ToString();
}
Where is struName ever set? You have a select query where CategoryName is suppose to = struName but I never see struName set. The problem may be your query does not return anything so the dr.Read never has any rows making struName always = string.Empty or "". Have to debugged your code to verify that the code drops into your while loop and sets struName to a value?

Nathan
Feb 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1556
by: Miguel Dias Moura | last post by:
Hello, I have a Drop Down List with 3 options. I want to redirect to a new page when an options is selected. I don't want to use a button. The redirection should be fired when the option is...
9
2153
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a...
6
1757
by: VB Programmer | last post by:
I have an itemtemplate in a datagrid. I'm trying to set it's value based on data. Having no trouble with the textbox. But, how do I do the same thing for a dropdownlist???? <ItemTemplate>...
6
1904
by: mahesh | last post by:
Hi friend, I am in deep trouble, I need to change the string in following format " 1.55576+2" in the floating point notation. that is i should have 155.576 as my output. Please suggest some...
0
1767
by: sonali | last post by:
I Have A Grid With Drop Down List As Template Column In Scrolling There Is some Problem Code Is As Follows: <style type="text/css"> .gridFixedHeader { background-color:white;...
7
4524
by: AG | last post by:
Hi, ASP.NET 2.0 web app I have a GridView utilizing template columns and bound to an objectdatasource. In the edit template of one column there is a dropdownlist bound to another...
5
1502
by: kalyani09 | last post by:
Hi, I have a problem in Java...Problem was... We have created one website called "STATS" in that website the user need to enter the Qty,Price,Date to confirm their Purchase Orders.After...
1
4430
by: djdarpan | last post by:
Hi, I am new with MySql and PHP. I have a problem while I am checking NULL value in database. I need If there is empty field in my table row return message "Somthing "and if there is...
1
5230
by: Laurahn | last post by:
Hi: How can i display tooltip message on a dropdownlist template control inside a GridView Footer. I found this code working well, but it dosen't work inside a gridview: </head> <body>...
0
6903
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6726
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5318
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
170
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.