I have an asp Repeater and its DataSource is a DataTable (with data from database). On the first loading of the page, the DataTable is filled from the db and then its datas are binded to the Repeater. Then I put the DataTable into the ViewState and on postback I use the DataTable from the ViewState, then it enables me to inject datas in database only after everything has been completed by the user.
Some lines can be added to the Repeater (by adding to the viewstate's DataTable and re-bind).
Here is the Repeater's code :
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:HiddenField ID="HdfHiddenRow" ClientIDMode="Static" runat="server" />
<asp:HiddenField ID="HdfHiddenId" ClientIDMode="Static" runat="server" />
<div style="display:none;">
<asp:Button ID="BtnHiddenButton" runat="server" Text="" OnClick="BtnHiddenButton_Click" />
</div>
<table id="TableEI" style="width: 800px; margin-left:50px;" cellpadding="0" cellspacing="0">
<asp:Repeater ID="Repeat_EffetsIndes" runat="server" OnItemDataBound="Repeat_EffetsIndes_ItemDataBound" >
<ItemTemplate>
<tr>
<td style="width: 431px;">
<asp:Label ID="LblEI" runat="server" />
</td>
<td class="auto-style1">
<asp:CheckBox ID="CheckOui" ClientIDMode="Static" runat="server" Text="Yes" onclick="CheckedLine(this)" />
</td>
<td>
<asp:CheckBox ID="CheckOui1" ClientIDMode="Static" runat="server" Enabled="false" Text="some text1" />
<br />
<asp:CheckBox ID="CheckOui2" ClientIDMode="Static" runat="server" Enabled="false" Text="some text2" />
<br />
<asp:CheckBox ID="CheckOui3" ClientIDMode="Static" runat="server" Enabled="false" Text="some text3" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
.....
[textbox + button to add new row there]
.....
</ContentTemplate>
</asp:UpdatePanel>
Check an example of rows from my Repeater :
http://img4.hostingpics.net/pics/356954example.png
When the 1st checkbox (Yes) is chcked : it enables the 3 right checkboxes. (this has been done thanks to javascript)
I had to give a unique ID to my 4 checkboxes on each row, and be able to identify which checkboxes have to be enabled when the parent is checked. I give a unique ID on ItemDataBound event of Repeater.
protected void Repeat_EffetsIndes_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataRowView drv = e.Item.DataItem as DataRowView;
((Label)e.Item.FindControl("LblEI")).Text = drv["Suivi_EffetsIndes_Label"].ToString();
CheckBox ParentCheckBox = ((CheckBox)e.Item.FindControl("CheckOui"));
CheckBox ChildCheckBox1 = ((CheckBox)e.Item.FindControl("CheckOui1"));
CheckBox ChildCheckBox2 = ((CheckBox)e.Item.FindControl("CheckOui2"));
CheckBox ChildCheckBox3 = ((CheckBox)e.Item.FindControl("CheckOui3"));
string _IdPrefix = Guid.NewGuid().ToString().Replace("-", "");
// Affectation d'un ID unique à chaque checkbox "Oui"
ParentCheckBox.ID = _IdPrefix;
// Concaténation de l'ID de la checkbox parent (Oui) et d'un chiffre pour identifier les checkboxes.
ChildCheckBox1.ID = _IdPrefix + "1";
ChildCheckBox2.ID = _IdPrefix + "2";
ChildCheckBox3.ID = _IdPrefix + "3";
}
The Problem
When one of the 3 right checkboxes is checked, i would like to directly update the correct value in the ViewState datatable (set field "checked" from 0 to 1).
The problem is that I have some trouble to catch the "CheckedChanged" of the checkboxes, don't know why, and also the "ID" of the checkboxes seem to always set to its default value so i can find them by writing "Repeater.Items[x].FindControl("CheckOui1") for example, and it would not have to be possible because I give them a new ID, and that's thanks to this one that i would like to find which checkbox is checked.
(apologies for my not perfect english writing)
The only problem I see in your code is the fact you're using GUID
to set your Checkboxes ID and that it's wrong, because every time you re-bind your repeater or refresh page, the ID will be completely different.
So I advice you to do the following steps:
Remove ClientIDMode
property from your checkboxes. By doing this, your checkboxes ID on HTML would be something like this Repeat_EffectsIndes_CheckOui_0
(you can identify each unique ID using Firebug or your browser's option Inspect Element).
On Javascript, verify which checkbox is checked, get the ID and enable the other 3 checkboxes (the same you already have done I suppose). The ID of the other 3 checkboxes will be like Repeat_EffectsIndes_CheckOui_0_CheckOui1
(for the rest is the same, except the last number), the 0 (zero) is the row index.
Finally, on your page code-behind, use the Repeater.Items[x].FindControl("<CheckBoxID>")
where <CheckBoxID>
is the control ID.
Hope it helps.