Adding an HtmlInputControl and writing the data

D

DomNewbie

I have added a template column with a file field in the
EditItemTemplate. The ItemTemplate contains a databound label. I'm
wondering how best to not lose the data when invoking the edit command
and how best to write data back to the database when a new file is
selected.

Below is as far as I've got!!

private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

string[] values=new string[16] ;
bool isFile=false;
DataTable dt=td.Projects;

// Gets the value of the key field of the row being updated
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();



// Gets the value the TextBox control
for(int i = 1; i < e.Item.Cells.Count-1; i++)
{
if
(e.Item.Cells.Controls[0].GetType().ToString()=="System.Web.UI.LiteralControl")
{
isFile=true;
LiteralControl lc =
(LiteralControl)(e.Item.Cells.Controls[0]);
string filenam=lc.Text;


}
if
(e.Item.Cells.Controls[0].GetType().ToString()=="System.Web.UI.WebControls.TextBox")
{
TextBox tb = (TextBox)(e.Item.Cells.Controls[0]);
values= tb.Text;
if (isFile)
{
values[i-1]= tb.Text;
isFile=false;
}
}

}

int j=0;

foreach (DataRow r in dt.Rows)
{
if (r.ItemArray[0].ToString() ==key)
{

for(int i = 1; i < e.Item.Cells.Count-1; i++)
{
try
{
r = values;
}
catch
{
lblError.Text = lblError.Text + "\r\n" + "Invalid
value in the field " + dt.Columns.ColumnName + "**";
}
}
}
j +=1;

}


td.updateProjects(dt);
DataGrid1.EditItemIndex = -1;
this.DataGrid1.DataSource=dt;

DataGrid1.DataBind();

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top