If anyone has a better way than what I show below, I'd really like to know.
I have extensively researched this exact same question and no one has every
suggested anything other than what the code below does. Basically you have
too loop through the Form collection:
//This line is in your Page code-behind
dataClass.LoopThroughFormCollection(Request.Form); // pass Request.Form to a
method that will loop through it.
// This method is in a separate class
public void
LoopThroughFormCollection(System.Collections.Speci alized.NameValueCollection
formCollection) {
int currentControlNumber = 0; // Your TextBox will appear many times -
ASP.NET will number each one uniquely - so you might want to parse this out
string strTemp = "";
string controlName = "";
int delPos = 0; //delimiter position
string controlValue = "";
String[] arrayFormKeys = formCollection.AllKeys;
// Loop through all of the controls in the Form collection
for (loop = 0; loop < arrayFormKeys.Length; loop++) {
// Parse out the control name and number from the form KEY value, and then
get the value associated with that KEY.
// This is an example of what we're parsing from the form KEY value:
"MyDataListName:_ctl1:MyTextBox"
if (arrayFormKeys[loop].StartsWith("MyDataListName")) {
strTemp = arrayFormKeys[loop].Replace("MyDataListName:_ctl", "");
delPos = strTemp.IndexOf(":", 0); // delimiter position
currentControlNumber = Convert.ToInt32(strTemp.Substring(0, delPos));
controlName = strTemp.Substring(delPos + 1, (strTemp.Length - (delPos +
1)));
controlValue = formCollection[arrayFormKeys[loop]];
// At this point you have everything you need to know about the current
row in your DataList that was returned via the Form collection
if (controlName == "MyTextBox") {
// Do something here; write textbox value to db or whatever.
}
}
}
}
-HTH
<bw****@lbrspec.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I am developing a web form which is going to be used for manufacturing
input. The form uses a DataList which list a batch of parts that may
range anywhere from 1-9 parts. The DataList contains 6 textboxes
pre-fill with data (reason for using datalist) which will capture user
input and changes to the textboxes. So the 6 textboxes in columns will
be constant but the rows will vary representing each part. I am
looking to loop through each row and grab the values of the 6
textboxes. Without using the Edit commands on the datalist is it
possible to find the textbox values in each row. I want to have the
whole datalist read back into the database on a button click. Is this
possible. Best ways of going about it. Hope this makes sense.
Thanks,
Brett