code:
AutoGenerateColumns = "false" Font-Names = "Arial" Width = "550px"
Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B"
HeaderStyle-BackColor = "skyblue"
AllowPaging ="true" ShowFooter = "true"
OnPageIndexChanging = "OnPaging" onrowediting="EditCustomer"
onrowupdating="UpdateCustomer" onrowcancelingedit="CancelEdit"
PageSize = "10" >
Text='<%# Eval("Course_id")%>'>
Text='<%# Eval("Course_no")%>'>
Text='<%# Eval("Title")%>'>
Text='<%# Eval("site_id")%>'>
Text='<%# Eval("site_no")%>'>
Text='<%# Eval("site_name")%>'>
Text='<%# Eval("display")%>'>
Text='<%# Eval("max_students")%>'>
SelectCommand="SELECT [Course_id], [Course_no] FROM [Course_table]">
c#code:
SQLLogic dl = new SQLLogic();
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
// if(true)
{
BindData();
}
}
catch (Exception ex)
{
err_Label.Text = (ex.Message);
}
}
private void BindData()
{
//string strSql = "select course_table.course_id, course_table.course_no,course_table.title,siteinfo_table.site_id,siteinfo_table.site_no,siteinfo_table.site_name,siteinfo_table.course_time,siteinfo_table.max_students from course_table, siteinfo_table where course_table.course_id = siteinfo_table.course_id";
string strSql = "" +
" select " +
" course_table.course_id " +
" , course_table.course_no " +
" ,course_table.title " +
" ,siteinfo_table.site_id " +
" ,siteinfo_table.site_no " +
" ,siteinfo_table.site_name " +
" ,b.display" +
" ,siteinfo_table.max_students " +
" from course_table, siteinfo_table " +
" join Rotation b " +
" on b.code=siteinfo_table.Rotation " +
" where course_table.course_id = siteinfo_table.course_id ";
DataSet ds = dl.CSRMyExecuterQuery(strSql);
GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
//((DropDownList)Page.FindControl("ddl1")).DataSource = coursesarray;
//((DropDownList)Page.FindControl("ddl1")).DataBind();
}
protected void EditCustomer(object sender, GridViewEditEventArgs e)
{
GridView2.EditIndex = e.NewEditIndex;
BindData();
}
protected void ddl_courseno_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
err_Label.Visible = true;
err_Label.Text = "ddl selectindexchange method run";
DropDownList ddl1 = (DropDownList)sender;
int RowIndex = ((GridViewRow)ddl1.NamingContainer).RowIndex;
string site_id = GridView2.DataKeys[RowIndex].Value.ToString();
string strSql = "select Title from Course_table where Course_id = '" + ddl1.SelectedValue.ToString() + "'";
DataSet ds = dl.CSRMyExecuterQuery(strSql);
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
err_Label.Text = dr["Title"].ToString();
//how do i assign the coursename here????????
}
}
else
{
err_Label.Text = "No Details Avaliable";
}
}
catch (Exception ex)
{
err_Label.Text = ex.Message;
}
}
protected void CancelEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView2.EditIndex = -1;
BindData();
}
protected void UpdateCustomer(object sender, GridViewUpdateEventArgs e)
{
string course_id = ((DropDownList)GridView2.Rows[e.RowIndex].FindControl("ddl_course_no")).SelectedValue.ToString();
}
int i = -1;
// string str = "update siteinfo_table set coures_id=" + course_id.ToString() + " where site_id='" + site_id + "'";
// i = dl.CSRExecuteNonQuery(str);
i = 1;
if (i >= 0)
{
err_Label.Visible = true;
err_Label.Text = "updated";
}
string strSql1 = " select course_table.course_id, course_table.course_no, course_table.title, siteinfo_table.site_id,siteinfo_table.site_no, siteinfo_table.site_name,b.display,siteinfo_table.max_students from course_table, siteinfo_table join Rotation b on b.code=siteinfo_table.Rotation where course_table.course_id = siteinfo_table.course_id";
DataSet ds1 = dl.CSRMyExecuterQuery(strSql1);
GridView2.EditIndex = -1;
GridView2.DataSource = ds1.Tables[0];
GridView2.DataBind();
// BindData();
}
2 Answers
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 questionsForums
Top experts
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
vijay172 reputationPosted Feb 2, 2011, 9:13 PM EST
try this steps you have TO add this code into grid view row command properties..add dropdownlist command name IN CLIENT SIDE..
if e. commandname="Given id in client side " then
write the update sql command by selecting the field dropdown,after get the data from database load into particular field..
check the link it may useful... GRID VIEW OR CLICK HERE
Bharat Bhushan177 reputationPosted Feb 2, 2011, 9:18 PM EST
http://www.codegain.com/articles/aspnet/gridcontrols/how-to-avoid-duplicate-records-insertion-with-gridview-in-aspnet.aspx