- Joined
- Oct 20, 2009
- Messages
- 1
- Reaction score
- 0
I have a fairly simple datagrid, and had to add some seperator rows. Once I did this I noticed that my delete column was acting a little funny. Upon further investigation I realized that it is only the last item in the datagraid that will not delete if there is only one header and then the wrong rows get deleted when there are more then one dynamic rows inserted.
The datagrid seems to be losing count of where it is and what its supposed to do once the new title rows are added. Has anyone ran into this? Here is some of my code --
<asp
ataGrid ID="dgAttachments"
CssClass="striped_table"
GridLines="None"
runat="server"
ShowHeader="true"
DataKeyField="attachmentid"
OnDeleteCommand="DeleteMyAttachment"
Width="100%"
AutoGenerateColumns="false"
OnItemDataBound="MyAttachmentsDataBound"
ItemStyle-CssClass="oddrow"
AlternatingItemStyle-CssClass="evenrow">
<HeaderStyle CssClass="headerStriped" />
<Columns>
<asp:HyperLinkColumn Target="_blank" HeaderText="File Name" DataNavigateUrlField="attachmentid" DataNavigateUrlFormatString="/aime/util/attachment.aspx?attachmentid={0}" DataTextField="original_file_name"></asp:HyperLinkColumn>
<asp:BoundColumn HeaderText="File Size" DataField="filesize"></asp:BoundColumn>
<asp:BoundColumn HeaderText="Uploaded By" DataField="uploaded_by"></asp:BoundColumn>
<acntrl
ateColumn HeaderText="Uploaded Date" DataField="time_stamp" />
<asp:ButtonColumn CommandName="Delete" ButtonType="linkbutton" Text="Delete"></asp:ButtonColumn>
</Columns>
</asp
ataGrid>
int intPrevDocLevel = 0;
int added = 1;
public void DeleteMyAttachment(object sender, DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == "Delete")
{
AttachmentID = Util.forceInt(dgAttachments.DataKeys[e.Item.ItemIndex].ToString());
DeleteAttachment();
litULMessage.Text = "File Successfully Deleted";
}
}
catch (Exception x)
{
//Define your error here. If in a class, pass x.Message, if in a .aspx page, just pass x
AimeError newErr = new AimeError(x, 0, "DeleteMyAttachment", "AimeFileUpload.ascx");
}
}
public void MyAttachmentsDataBound(object sender, DataGridItemEventArgs e)
{
try
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
System.Data.Common.DbDataRecord r = (System.Data.Common.DbDataRecord)e.Item.DataItem;
bool blnAdmin = Util.forceBool(r["attach_owner"].ToString());
int intAttachmentID = (int)r["attachmentid"];
DataGrid DG = (DataGrid)sender;
if (!blnAdmin)
{
e.Item.Cells[4].Text = "";
}
if (UploadType == 1 || UploadType == 2)
{
if (intPrevDocLevel != (int)r["doc_level"])
{
DataGridItem headerRow = new DataGridItem(e.Item.ItemIndex + added, e.Item.ItemIndex + added, ListItemType.Item);
headerRow.CssClass = "fixedSubTitle";
TableCell cellTitle = new TableCell();
cellTitle.Text = (int)r["doc_level"] == 1 ? "Current Attachments" : "Parent Attachments";
cellTitle.ColumnSpan = 5;
cellTitle.Style.Add("padding-left", "2px");
headerRow.Cells.Add(cellTitle);
DG.Controls[0].Controls.AddAt(e.Item.ItemIndex + added, headerRow);
intPrevDocLevel = (int)r["doc_level"];
added++;
}
}
}
}
catch (Exception x)
{
//Define your error here. If in a class, pass x.Message, if in a .aspx page, just pass x
AimeError newErr = new AimeError(x, 0, "OnDGDataBind", "discussion_pop.aspx.cs");
}
}
The datagrid seems to be losing count of where it is and what its supposed to do once the new title rows are added. Has anyone ran into this? Here is some of my code --
<asp
CssClass="striped_table"
GridLines="None"
runat="server"
ShowHeader="true"
DataKeyField="attachmentid"
OnDeleteCommand="DeleteMyAttachment"
Width="100%"
AutoGenerateColumns="false"
OnItemDataBound="MyAttachmentsDataBound"
ItemStyle-CssClass="oddrow"
AlternatingItemStyle-CssClass="evenrow">
<HeaderStyle CssClass="headerStriped" />
<Columns>
<asp:HyperLinkColumn Target="_blank" HeaderText="File Name" DataNavigateUrlField="attachmentid" DataNavigateUrlFormatString="/aime/util/attachment.aspx?attachmentid={0}" DataTextField="original_file_name"></asp:HyperLinkColumn>
<asp:BoundColumn HeaderText="File Size" DataField="filesize"></asp:BoundColumn>
<asp:BoundColumn HeaderText="Uploaded By" DataField="uploaded_by"></asp:BoundColumn>
<acntrl
<asp:ButtonColumn CommandName="Delete" ButtonType="linkbutton" Text="Delete"></asp:ButtonColumn>
</Columns>
</asp
int intPrevDocLevel = 0;
int added = 1;
public void DeleteMyAttachment(object sender, DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == "Delete")
{
AttachmentID = Util.forceInt(dgAttachments.DataKeys[e.Item.ItemIndex].ToString());
DeleteAttachment();
litULMessage.Text = "File Successfully Deleted";
}
}
catch (Exception x)
{
//Define your error here. If in a class, pass x.Message, if in a .aspx page, just pass x
AimeError newErr = new AimeError(x, 0, "DeleteMyAttachment", "AimeFileUpload.ascx");
}
}
public void MyAttachmentsDataBound(object sender, DataGridItemEventArgs e)
{
try
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
System.Data.Common.DbDataRecord r = (System.Data.Common.DbDataRecord)e.Item.DataItem;
bool blnAdmin = Util.forceBool(r["attach_owner"].ToString());
int intAttachmentID = (int)r["attachmentid"];
DataGrid DG = (DataGrid)sender;
if (!blnAdmin)
{
e.Item.Cells[4].Text = "";
}
if (UploadType == 1 || UploadType == 2)
{
if (intPrevDocLevel != (int)r["doc_level"])
{
DataGridItem headerRow = new DataGridItem(e.Item.ItemIndex + added, e.Item.ItemIndex + added, ListItemType.Item);
headerRow.CssClass = "fixedSubTitle";
TableCell cellTitle = new TableCell();
cellTitle.Text = (int)r["doc_level"] == 1 ? "Current Attachments" : "Parent Attachments";
cellTitle.ColumnSpan = 5;
cellTitle.Style.Add("padding-left", "2px");
headerRow.Cells.Add(cellTitle);
DG.Controls[0].Controls.AddAt(e.Item.ItemIndex + added, headerRow);
intPrevDocLevel = (int)r["doc_level"];
added++;
}
}
}
}
catch (Exception x)
{
//Define your error here. If in a class, pass x.Message, if in a .aspx page, just pass x
AimeError newErr = new AimeError(x, 0, "OnDGDataBind", "discussion_pop.aspx.cs");
}
}