here is my .aspx page
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<tr bgcolor="maroon">
<th>
Subject Id
</th>
<th>
Subject Name
</th>
<th>
Obtained Marks
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblSubjectId" runat="Server" Text='<%#Eval("Subject_Id")%>'></asp:Label>
</td>
<td>
<asp:Label ID="lblSubjectName" runat="Server" Text='<%#Eval("Subject_Name")%>'></asp:Label>
</td>
<td>
<asp:TextBox ID="txtMarks" runat="server" ></asp:TextBox>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
c# - code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.PopulateRepeater();
}
}
private void PopulateRepeater()
{
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DbConnect"].ConnectionString);
cn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Assign_Subjects where Faculty_Id='" + Session["User_Id"].ToString() + "' and Semester='" + ddlFacSem.SelectedValue + "'", cn);
//and Semester='" + ddlFacSem.SelectedValue + "' and Course_Id='" +Session["Course_Id"].ToString()+ "'
//lblFacBranch.Text = Session["Course_Id"].ToString();
Repeater1.DataSource = cmd.ExecuteReader();
Repeater1.DataBind();
}
protected void btnInsert_Click(object sender, EventArgs e)
{
foreach (RepeaterItem repeaterItem in Repeater1.Items)
{
string subjectId = (repeaterItem.FindControl("lblSubjectId") as Label).Text.Trim();
string subjectName = (repeaterItem.FindControl("lblSubjectName") as Label).Text.Trim();
string marks = (repeaterItem.FindControl("txtMarks") as TextBox).Text.Trim();
this.SaveData(subjectId, subjectName, marks);
}
}
// Insert Code....
private void SaveData(string subjectId, string subjectName, string marks)
{
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DbConnect"].ConnectionString);
cn.Open();
SqlCommand cmd = new SqlCommand("Insert into EResult(Enroll_Number,Student_Name,Course_Id,Semester,Subject_Id,Subject_Name,MarksObtained,Exam_Type)values('" + ddlTraineeNo.SelectedValue + "','" + lblSalutation.Text + " " + lblFName.Text + " " + lblLName.Text + "','" + ddlBranch.SelectedValue + "','" + ddlSemester.SelectedValue + "','" + subjectId + "','" + subjectName + "','" + marks + "','" + ddlExamType.SelectedValue + "')", cn);
Repeater1.DataSource = cmd.ExecuteReader();
//Display a popup which indicates that the record was successfully inserted
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Script", "alert('Marks Added Successfuly. !!');", true);
cn.Close();
cmd.Connection.Close();
cmd.Connection.Dispose();
}
current repeater looks as...
Subject_Id Subject_Name Marks
s1(lable) subject1(lable) 56(textbox)
> Now, i want to make Upation with repeater (in same application).
> want to update Marks(into textboxes only, sub_id and name fatched from database dynamically) in each row of repeater.... how is it possible ??
thanks