when i enter employee_id nd press SHOW button then
show griedview data for perticular employee_id data
Using visual studio 2008 c#.net with sql server 2005
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 6, 2014, 4:36 AM EDT
SelectCommand="SELECT [FirstName], [SecondName], [ThirdName], [EmployeeID] FROM [Users] WHERE ([EmployeeID] = @EmployeeID)"
>
in .cs file
protected void btnShow_Click(object sender, EventArgs e)
{
ParameterCollection prm = SqlDataSource1.SelectParameters;
prm[0].DefaultValue = txtEmpID.Text;
}
Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 6, 2014, 3:05 AM EDT
public Datatable bindGridview(int empID)
{
//Call the store procedure or sql query to get the data from database
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count == 0)
{
GridView1.Visible = false;
}
else
{
GridView1.Visible = true;
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
bindGridview(empID)
}
Hope this will help.
pankaj diyora22 reputationPosted Apr 6, 2014, 4:11 AM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 6, 2014, 5:04 AM EDT
Click on drop down list in write this code
{
string str = "server = MUNESH\\SQL2008R2;Database=datastore;UID=sa;Password=123;";
SqlConnection con = new SqlConnection(str);
string query = "select * from tablename where name = '"+dropdownlist.text+"' ";
SqlCommand cmd = new SqlCommand( query,con);
sqldatareader dbr;
try
{
con.open();
dbr = cmd.executereader();
while(dbr.read())
{
string sID = (string) dbr["ID"].tostring;
string sname = (string) dbr["name"] // name is string value
string sage = (string) dbr["age"].tostring;
textbox1.text = sid;
textbox2.text = sname;
textbox3.text = sage;
showgrid();
}
catch(execption es)
{
messagebox.show(es.message);
}
}
}If you want to more operation with grid view or data gridview then go to my C-sharp corner blogs.
pankaj diyora22 reputationPosted Apr 7, 2014, 10:59 AM EDT
Update Employess Details
Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 7, 2014, 9:36 PM EDT
Can you please send the aspx and aspx.cs code so I can look on it.