Empty upload field overwriting database field problem

 Could someone please help me find the missing piece to this puzzle.  My issue is when i execute this form without entering a new image in upload field, it overwrites the field in the database.  I'm not to sure how to pass the value, or just not update that field.   Any help would be great. 


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>

<script runat="server">

        Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)

        Dim imageBytes As Byte()
    
        imageBytes = DirectCast(e.NewValues.Item("Org_Image"), Byte())
        If (imageBytes.Length = 0) Then
            e.NewValues.Item("Org_Image") = e.OldValues.Item("Org_Image")
        End If

        End Sub

</script>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataKeyNames="ListId" DataSourceID="SqlDataSource1" Width="400px">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowSelectButton="True" />
                <asp:BoundField DataField="ListId" HeaderText="ListId" InsertVisible="False" ReadOnly="True"
                    SortExpression="ListId" />
                <asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" />
                <asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
                <asp:BoundField DataField="Name_Title" HeaderText="Name_Title" SortExpression="Name_Title" />
            </Columns>
        </asp:GridView>
         
        <br />
        <br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ListId"
    DataSourceID="SqlDataSource2" Height="50px" Width="400px" OnItemUpdating="DetailsView1_ItemUpdating" >
    <Fields>
    <asp:BoundField DataField="ListId" HeaderText="ListId" InsertVisible="False" ReadOnly="True" SortExpression="ListId" />

    <asp:TemplateField HeaderText="Category" SortExpression="Category">
        <EditItemTemplate>
        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource4"
            DataTextField="Category" DataValueField="Category" DataMember="DefaultView" SelectedValue='<%# Bind("Category") %>'>
        </asp:DropDownList>
        </EditItemTemplate>
        <ItemTemplate>
        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Category") %>'></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>

    <asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
    <asp:BoundField DataField="Name_Title" HeaderText="Name/Title" SortExpression="Name_Title" />
    <asp:BoundField DataField="Serial_number" HeaderText="Serial number" SortExpression="Serial_number" />
    <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />

       <asp:TemplateField HeaderText="Condition" SortExpression="Condition">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource5"
                    DataTextField="condition" DataValueField="condition" SelectedValue='<%# Bind("condition") %>'>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Condition") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

    <asp:BoundField DataField="Purchased_From" HeaderText="Purchased From" SortExpression="Purchased_From" />
    <asp:BoundField DataField="Purchase_Price" HeaderText="Purchase Price" SortExpression="Purchase_Price" />
    <asp:BoundField DataField="Purchase_Date" HeaderText="Purchase Date" SortExpression="Purchase_Date" />
    <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />

       <asp:TemplateField HeaderText="Image" SortExpression="Org_Image">
            <EditItemTemplate>
                <asp:FileUpload ID="FileUpload1" Runat="server" EnableViewState="True" FileBytes='<%# Bind("Org_Image") %>' />
            </EditItemTemplate>
            <ItemTemplate>
            <img src='Bandler.ashx?PhotoID=<%# Eval("ListId") %>' class="photo_198" style="border:2px solid white;width:100px;" alt='Thumbnail of Photo Number <%# Eval("ListId") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    <asp:CommandField ShowEditButton="True" />
    </Fields>
</asp:DetailsView>
        <br />
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Personal %>"
            SelectCommand="SELECT ListId, Category, Brand, Name_Title, Serial_number, Description, Condition, Purchased_From, Purchase_Price, Purchase_Date, Notes, Org_Image FROM Stein_List WHERE (ListId = @ListId)"
            UpdateCommand="UPDATE Stein_List SET Category = @Category, Brand = @Brand, Serial_number = @Serial_number, Name_Title = @Name_Title, Description = @Description, Condition = @Condition, Purchased_From = @Purchased_From, Purchase_Price = @Purchase_Price, Purchase_Date = @Purchase_Date, Notes = @Notes, Org_Image = @Org_Image WHERE (ListId = @ListId)">
            <UpdateParameters>
                <asp:Parameter Name="Category" />
                <asp:Parameter Name="Brand" />
                <asp:Parameter Name="Serial_number" />
                <asp:Parameter Name="Name_Title" />
                <asp:Parameter Name="Description" />
                <asp:Parameter Name="Condition" />
                <asp:Parameter Name="Purchased_From" />
                <asp:Parameter Name="Purchase_Price" />
                <asp:Parameter Name="Purchase_Date" />
                <asp:Parameter Name="Notes" />
                <asp:Parameter Name="Org_Image" ConvertEmptyStringToNull="true" />
                <asp:Parameter Name="ListId" />
            </UpdateParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="ListId" PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Personal %>"
            DeleteCommand="DELETE FROM Stein_List WHERE (ListId = @ListId)" SelectCommand="SELECT ListId, Category, Brand, Name_Title FROM Stein_List">
            <DeleteParameters>
                <asp:Parameter Name="ListId" />
            </DeleteParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:Personal %>"
            SelectCommand="SELECT [Category] FROM [Categories]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:Personal %>"
            SelectCommand="SELECT [condition] FROM [Condition]"></asp:SqlDataSource>

    </div>
    </form>
</body>
</html>
0
jzqrtl1
3/20/2006 5:13:55 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

5 Replies
946 Views

Similar Articles

[PageSpeed] 11
Get it on Google Play
Get it on Apple App Store

I suggest you have a look at this article: http://blogs.msdn.com/jdixon/articles/495408.aspx

and this forum thread http://forums.asp.net/556051/ShowPost.aspx  that discuss using file upload inside a details view.

Compare the code to yours to figure out exactly what your missing.

I am also not sure why you want to do         Dim imageBytes As Byte()
    
        imageBytes = DirectCast(e.NewValues.Item("Org_Image"), Byte())

When you can easily check e.NewValues.Item("Org_Image") != null && e.NewValues.Item("Org_Image").ToString().Lenth > 0

Then only if needed, perform your byte case, or put the oldvalue in place.

 

 


Jonathan Minond
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
0
jminond
3/20/2006 6:19:47 PM
I did look at the blog article, the problem is his is not editing the form (image) , just adding a new image.
All i want to do is update the form in the page and if i don't want to upload a new image pass the existing value back to the Db or not update the field all together.
0
jzqrtl1
3/20/2006 6:46:38 PM

try.... like i mentioned before....

e.NewValues.Item("Org_Image") != null && e.NewValues.Item("Org_Image").ToString().Lenth > 0

    then do your direct cast

else

   e.NewValue.... = e.Oldvalue

 

you could also, take a more involved apporach, and control the update sql statement, to say something like

if Len(@imgByteParam) = 0 or @imgByteParam = existing image bytes, then don't update.

 


Jonathan Minond
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx
0
jminond
3/20/2006 7:09:14 PM
Thanks, i will try to get this to work.
0
jzqrtl1
3/20/2006 7:24:03 PM

hi ,i have file upload in detailsview in a update panel and through update panel <asp:PostBackTrigger> i am able to upload the images but when i update the record in

detailsview and don''t  upload an image the previous uploaded images is cleared out in database and null be inserted. so can any one solve this problem.

 

<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" CodeFile="News.aspx.cs" Inherits="Admin_News" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

 

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="LightGoldenrodYellow"

BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="newsid"

DataSourceID="SqlDataSource1" Height="50px" Style="left: 87px; position: relative;

top: 17px" Width="125px" AllowPaging="True" Font-Names="Times New Roman" Font-Size="Small" ForeColor="Black" GridLines="None" OnItemInserting="DetailsView1_ItemInserting" OnItemUpdating="DetailsView1_ItemUpdating" OnDataBound="DetailsView1_DataBound" OnItemDeleting="DetailsView1_ItemDeleting" OnItemInserted="DetailsView1_ItemInserted" OnItemDeleted="DetailsView1_ItemDeleted" OnItemUpdated="DetailsView1_ItemUpdated">

<FooterStyle BackColor="Tan" />

<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />

<Fields>

<asp:TemplateField HeaderText="newsdate" SortExpression="newsdate">

<EditItemTemplate>

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("newsdate") %>'></asp:TextBox>

<ajaxToolkit:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="TextBox1" PopupPosition="TopRight">

</ajaxToolkit:CalendarExtender>

</EditItemTemplate>

<InsertItemTemplate>

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("newsdate") %>'></asp:TextBox>

<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd-MM-yyyy"

TargetControlID="TextBox1">

</ajaxToolkit:CalendarExtender>

</InsertItemTemplate>

<ItemTemplate>

<asp:Label ID="Label1" runat="server" Text='<%# Bind("newsdate") %>'></asp:Label>

</ItemTemplate>

<HeaderStyle Font-Bold="True" />

</asp:TemplateField>

<asp:BoundField DataField="newsheading" HeaderText="newsheading" SortExpression="newsheading" >

<HeaderStyle Font-Bold="True" />

</asp:BoundField>

<asp:TemplateField HeaderText="newsdetail" SortExpression="newsdetail">

<EditItemTemplate>

<asp:TextBox ID="TextBox2" runat="server" Height="103px" Style="position: relative"

Text='<%# Bind("newsdetail") %>' TextMode="MultiLine" Width="268px"></asp:TextBox>

</EditItemTemplate>

<InsertItemTemplate>

<asp:TextBox ID="TextBox2" runat="server" Height="103px" Text='<%# Bind("newsdetail") %>'

TextMode="MultiLine" Width="268px"></asp:TextBox>

</InsertItemTemplate>

<ItemTemplate>

<asp:Label ID="Label3" runat="server" Text='<%# Bind("newsdetail") %>'></asp:Label>

</ItemTemplate>

<HeaderStyle Font-Bold="True" />

</asp:TemplateField>

<asp:TemplateField HeaderText="showornot" SortExpression="showornot">

<EditItemTemplate>

<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("showornot") %>' />

</EditItemTemplate>

<InsertItemTemplate>

<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("showornot") %>' />

</InsertItemTemplate>

<ItemTemplate>

<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("showornot") %>' Enabled="false" />

</ItemTemplate>

<HeaderStyle Font-Bold="True" />

</asp:TemplateField>

 

 

<asp:TemplateField HeaderText="imagename" SortExpression="imagename">

<EditItemTemplate>

 

<asp:FileUpload ID="FileUpload1" runat="server" Style="position: relative" />

 

 

</EditItemTemplate>

<InsertItemTemplate>

 

<asp:FileUpload ID="FileUpload1" runat="server" Style="position: relative" />

 

</InsertItemTemplate>

<ItemTemplate>

<asp:Label ID="Label2" runat="server" Text='<%# Bind("imagename") %>'></asp:Label>

</ItemTemplate>

<HeaderStyle Font-Bold="True" />

</asp:TemplateField>

<asp:TemplateField ShowHeader="False">

<EditItemTemplate>

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"

Text="Update"></asp:LinkButton>

<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"

Text="Cancel"></asp:LinkButton>

</EditItemTemplate>

<InsertItemTemplate>

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert"

Text="Insert"></asp:LinkButton>

<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"

Text="Cancel"></asp:LinkButton>

</InsertItemTemplate>

<ItemTemplate>

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"

Text="Edit"></asp:LinkButton>

<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="New"

Text="New"></asp:LinkButton>

<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete"

OnClientClick="return confirm('Do you want to delete?')" Text="Delete"></asp:LinkButton>

</ItemTemplate>

<HeaderStyle Font-Bold="True" />

</asp:TemplateField>

</Fields>

<HeaderStyle BackColor="Tan" Font-Bold="True" Font-Size="X-Large" />

<EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />

<CommandRowStyle Font-Names="Times New Roman" Font-Size="Small" />

<AlternatingRowStyle BackColor="PaleGoldenrod" />

</asp:DetailsView>

<asp:Label ID="Label5" runat="server" Font-Bold="True" Font-Names="Times New Roman"

Font-Size="Small" Style="left: 118px; position: relative; top: -247px" Text="Record inserted successfully."

Visible="False"></asp:Label>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"

DeleteCommand="DELETE FROM [news] WHERE [newsid] = @newsid" InsertCommand="INSERT INTO [news] ([newsdate], [newsheading], [newsdetail], [showornot], [imagename], [imagesize], [imagetype]) VALUES (@newsdate, @newsheading, @newsdetail, @showornot, @imagename, @imagesize, @imagetype)"

SelectCommand="SELECT * FROM [news]" UpdateCommand="UPDATE [news] SET [newsdate] = @newsdate, [newsheading] = @newsheading, [newsdetail] = @newsdetail, [showornot] = @showornot, [imagename] = @imagename, [imagesize] = @imagesize, [imagetype] = @imagetype WHERE [newsid] = @newsid">

<DeleteParameters>

<asp:Parameter Name="newsid" Type="Int32" />

</DeleteParameters>

<UpdateParameters>

<asp:Parameter Name="newsdate" Type="DateTime" />

<asp:Parameter Name="newsheading" Type="String" />

<asp:Parameter Name="newsdetail" Type="String" />

<asp:Parameter Name="showornot" Type="Boolean" />

<asp:Parameter Name="imagename" Type="String" />

<asp:Parameter Name="imagesize" Type="String" />

<asp:Parameter Name="imagetype" Type="String" />

<asp:Parameter Name="newsid" Type="Int32" />

</UpdateParameters>

<InsertParameters>

<asp:Parameter Name="newsdate" Type="DateTime" />

<asp:Parameter Name="newsheading" Type="String" />

<asp:Parameter Name="newsdetail" Type="String" />

<asp:Parameter Name="showornot" Type="Boolean" />

<asp:Parameter Name="imagename" Type="String" />

<asp:Parameter Name="imagesize" Type="String" />

<asp:Parameter Name="imagetype" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

 

 

<br />

 

 

 

 

 

 

&nbsp;<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"

BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="newsid"

DataSourceID="SqlDataSource12" Style="position: relative" EnableTheming="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDeleted="GridView1_RowDeleted">

<FooterStyle BackColor="White" ForeColor="#000066" />

<RowStyle Font-Names="Times New Roman" Font-Size="X-Small" ForeColor="#000066" />

<Columns>

<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

<asp:BoundField DataField="newsid" HeaderText="newsid" InsertVisible="False" ReadOnly="True"

SortExpression="newsid" />

<asp:BoundField DataField="newsdate" HeaderText="newsdate" SortExpression="newsdate" />

<asp:BoundField DataField="newsheading" HeaderText="newsheading" SortExpression="newsheading" />

<asp:BoundField DataField="newsdetail" HeaderText="newsdetail" SortExpression="newsdetail" />

<asp:CheckBoxField DataField="showornot" HeaderText="showornot" SortExpression="showornot" />

<asp:BoundField DataField="imagename" HeaderText="imagename" SortExpression="imagename" />

<asp:BoundField DataField="imagesize" HeaderText="imagesize" SortExpression="imagesize" />

<asp:BoundField DataField="imagetype" HeaderText="imagetype" SortExpression="imagetype" />

</Columns>

<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />

<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />

<HeaderStyle BackColor="#006699" Font-Bold="True" Font-Size="XX-Small" ForeColor="White" />

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource12" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"

DeleteCommand="DELETE FROM [news] WHERE [newsid] = @newsid" InsertCommand="INSERT INTO [news] ([newsdate], [newsheading], [newsdetail], [showornot], [imagename], [imagesize], [imagetype]) VALUES (@newsdate, @newsheading, @newsdetail, @showornot, @imagename, @imagesize, @imagetype)"

SelectCommand="SELECT * FROM [news]" UpdateCommand="UPDATE [news] SET [newsdate] = @newsdate, [newsheading] = @newsheading, [newsdetail] = @newsdetail, [showornot] = @showornot, [imagename] = @imagename, [imagesize] = @imagesize, [imagetype] = @imagetype WHERE [newsid] = @newsid">

<DeleteParameters>

<asp:Parameter Name="newsid" Type="Int32" />

</DeleteParameters>

<UpdateParameters>

<asp:Parameter Name="newsdate" Type="DateTime" />

<asp:Parameter Name="newsheading" Type="String" />

<asp:Parameter Name="newsdetail" Type="String" />

<asp:Parameter Name="showornot" Type="Boolean" />

<asp:Parameter Name="imagename" Type="String" />

<asp:Parameter Name="imagesize" Type="String" />

<asp:Parameter Name="imagetype" Type="String" />

<asp:Parameter Name="newsid" Type="Int32" />

</UpdateParameters>

<InsertParameters>

<asp:Parameter Name="newsdate" Type="DateTime" />

<asp:Parameter Name="newsheading" Type="String" />

<asp:Parameter Name="newsdetail" Type="String" />

<asp:Parameter Name="showornot" Type="Boolean" />

<asp:Parameter Name="imagename" Type="String" />

<asp:Parameter Name="imagesize" Type="String" />

<asp:Parameter Name="imagetype" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

</ContentTemplate>

<Triggers>

<asp:PostBackTrigger ControlID="DetailsView1" />

 

</Triggers>

</asp:UpdatePanel>

 

 

</asp:Content>

 

 

 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class Admin_News : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

if (DetailsView1.Rows.Count == 0)

{

DetailsView1.ChangeMode(
DetailsViewMode.Insert);

}

}

}

protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)

{

FileUpload fpl1 = (FileUpload)DetailsView1.FindControl("FileUpload1");

 

if(fpl1.HasFile)

{

e.Values[
"imagename"]=fpl1.FileName;

e.Values["imagesize"]=fpl1.PostedFile.ContentLength.ToString();

e.Values["imagetype"]=fpl1.PostedFile.ContentType;

}

else

{

e.Values[
"imagename"]="";

e.Values["imagesize"]="";

e.Values["imagetype"]="";

 

}

}

 

 

protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)

{

FileUpload fpl1 = (FileUpload)DetailsView1.FindControl("FileUpload1");if (fpl1.HasFile)

{

e.NewValues["imagename"] = fpl1.FileName;

e.NewValues["imagesize"] = fpl1.PostedFile.ContentLength.ToString();e.NewValues["imagetype"] = fpl1.PostedFile.ContentType;

}

if (!fpl1.HasFile)

{

e.NewValues["imagename"] = e.OldValues["imagename"];

e.NewValues["imagesize"] = e.OldValues["imagesize"];e.NewValues["imagetype"] = e.OldValues["imagetype"];

 

}

 

 

 

 

Label5.Visible =
true;

}

protected void DetailsView1_DataBound(object sender, EventArgs e)

{

 

}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

{

 

}

protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)

{

GridView1.DataBind();

Response.Redirect(
"News.aspx");

 

}

protected void DetailsView1_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)

{

 

 

 

}

protected void DetailsView1_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)

{

GridView1.DataBind();

Response.Redirect(
"News.aspx");

}

protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)

{

GridView1.DataBind();

Response.Redirect(
"News.aspx");

}

protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)

{

DetailsView1.DataBind();

}

}

 

0
shailesh_thapa
8/3/2008 6:23:09 AM
Reply:

Similar Artilces:

Problem in extracting null value from a grid view field to add to a database table field
Hi,I have a grid view and I am extracting a field value from the gridview corresponding to the chosen record via a radio button. Now for a particular record the field in grid view in asp.net is showing null value (blank). However when I am extracting this field value to add it to a database table the field in the table is populated by "&nbsp". I would like the field to be populated with null or even "". I am not sure how to do this. The following approach is failing:            If SelectedGridRow.Cells(5).Text = &qu...

Problems getting records into gridview from a decimal field in a database
 I have a datagid which takes data from a MS SQL database. All the data works fine except data from a decimal field. There is numbers in the table but alI get out is 0.0 in each row This is what the data looks like that is in the RiskScore field . I have also attached the code for the datagrid. Any ideas would be appreciated 50 71 69 NULL 38 42 34 66 16 57 NULL  &nbsp; &nbsp;&nbsp;&nbsp;<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" Border...

Get tables and fields from Informix database using VB.NET 2005
Hi, I'm relatively new to VB.NET 2005 Express, and I've managed to connect to an Informix database to display the contents of a specific table in a DataGridView. What I am struggling with is getting the table and fields names from the database, and putting the information into a TreeView so that the user can select the table in the tree, and update the grid with that selected table - but I can't seem to get it to collect the schema information. Ideally, I'd like to have the first node on the tree as the database name, followed by nodes for the table name, and the...

one Combbox field. How to get the other field ?
Hi I work with a accessdatasource and i have one field in my combobox. When i select one value from my combobox how can i get other field of the database in one textbox? Thank youMario Lopes HiWe may use the the Combbox's SelectedIndexChanged event to fetch the other field value either by fetching data from the database or else from a dataTable or dataView which the data is already filled.  Hope this will help.   And be sure to set AutoPostback = TRUE in your ComboBoxRegards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your ...

how to connect a database-field to an input-field
Hi There, I'm having a problem with connecting a field from a database to an input field. I do get a record but don't know how to attach this to a textbox. I thought the .value would do the trick but it doesn't... Here is my code: if DS.Tables(0).Rows.Count = 1 then naam.text = ds.Tables(0).Columns("Contact_naam").value.ToString end if myConnection.Close() End Sub </script> <html> <head> <link href="../../../styles/website.css" rel="stylesheet" soort="text/c...

Getting a field validator to hide other fields
Hello there. I have a page with a few fields, a few validators and a few buttons.When one button is clicked it causes some of my field validators to run. Is there a way to get a field validator to clear a label or textbox when it displays its own error message? You should use custom validator, in the ServerValidate event you can do all that you want like clearing the field value.Trirange Portal Server Online Demohttp://www.trirange.com/demo/ Hello, you should use a CustomValidor script and create a client-side javascript function to validate the data entered, and clear the field if the ...

getting the fields from the database
ok, I got a database that has many fields like around 25 fields. now I want to display those fields on my webform. what is the best way of doing it. What iam doing right now is I have a Storred procedure and i have OUTPUT parameters in it which return the value to be returned. but the problem is if I need to return all the field and bind it to the labels in the web form then i have to write 25 OUTPUT parameters variables., there must be a better wat :) ??HighOnCodingWanna get high! You could just use a SqlDataReader. But if all you need is one row of data then I'd probabl...

database fields problem
Ive created a class to hold various data items to print in a crystal report.  All worked well, I could pick from the various fields in the underlying class and they print on the report.  I needed to add a few extra fields to the class to put on the report.  When I refresh the report datasource, the new fields Ive added arent available in the report field exporer ???  Does anyone know how to do this ? I thought they should show up automatically ?? When you make changes to the data source (ie. add or removed fields and refresh your source) it won't work---for it to work y...

Empty Database Fields
Hi!I am using datalist which is attached with datatable. I have set the header in Datalist. When there is no data in the fileds/table, no data display but still it shows the header. How can I set that when there are no records, No display of datalist and its header. Thanks for your support. Hi sarahkhan, I hope you are binding the datalist using a dataset/datatable If so use the below custom function private void BindDataList() { //code to bind the datalist goes here if you are binding from code behind //DataList1.DataSource = (here goes your function to retrieve datatabl...

Displaying fields in same was as <%=(field)%> in .net
Hi, I am very new to .NET after aloways programming in ASP. Thought I would try and rewrite a site of mine using the new beta and Visual Web Developer. First impressions are good, there are some great tools there to save a load of time with the Datagrids etc. However I am stuck on how to do something I use 99% of my time in ASP and is holding me up! Before I would create a recordset using sSQL = "SELECT Name FROM Albums WHERE Uid = 1 ORDER BY Name" Set RsAlbum = Conn.Execute(sSQL) Name = RsAlbum("Name") Then in the HTML I could display the result by using <%=(Name)%> ...

problem with required field validator for mandatory fields
Hi there, In my webpage i m hving txtbox financial year , txtbox from year, txtbox endyear. Intially all three r mandatory fields. I want to do like this. when user enter value in financial year txtbox and submit then fromyear and endyear fields should not be mandatory. currently when submit it will check for all three. Is there any idea to implement it using codebehind or javascript. Thanks  hi try using textbox (financial year)  onblur event in javascript and here you can disable/enable required fields (Please first check value of text (financial year) in javascript.).u...

column field length < database field??
I have a datawindow in which I have a column field. in the column field the length that I have fixed only fit 40 chars. The database field length is 50 char. The question is...What property/ies Do I have to set for I could write 50 chars although they weren't seen altogether in the datawindow column field? Thanks in advance Export the DW into it's "source" code. Then change the column length to 50 and re-import the source code! regards ... Chris <jomarca1> wrote in message news:3ff16e26.547c.846930886@sybase.com... > I have a datawindow in whic...

CustomValidator searches database field (but it appears the problem is not finding the table in the database)
When attempting to use a CustomValidator search through a database to see if a TextBox input matches any entry in a field, an error "Cannot find table 0" is generated.  Previous posts suggest this error indicates it can't find the table, and though this is just a guess (maybe more than one problem present), I find it credible since the name of the table is "users" and at no point while revising the code did I find a place where I thought I should put the word "users" to direct the code to the appropriate table. This builds on the tutorial (with slight modification) found at: ...

Searching on empty database field
I want to get fields from my database based on whether it contains text or not.For that I use the input from a dropdownlist control.The following code is in my objectdatasource. <asp:ControlParameter ControlID="ddlExperience" Name="Experience" PropertyName="SelectedValue" Type="String" />Then in the code I do: If Experience <> "0" ThenIf Experience = "Yes" Then   mySQLCommand.CommandText += " AND ModelCategories.Experience<>''"ElseIf Experience = "No" ThenmySQLCommand.CommandText += " AND ModelCategories.Experience=''"End IfEnd IfThe funny thing is that the...

Web resources about - Empty upload field overwriting database field problem - asp.net.getting-started

Overwriting (computer science) - Wikipedia, the free encyclopedia
... , but its sources remain unclear because it lacks inline citations . Please improve this article by introducing more precise citations. Overwriting ...

Overwriting a Protected AVR Bootloader
A bootloader is typically used to update application code on a microcontroller. It receives the new program from a host, writes it to flash, ...

Google's Toolbar Reportedly Overwriting 404 Pages Across The Web
There are reports that the new beta version of the Google Toolbar is acting a bit evil. Reports are that when you install the toolbar and surf ...

How can I stop my camera overwriting old photos?
Two cameras with similar filename conventions can cause problems, but they are easily solved, says Rick Maybury

Resources last updated: 11/28/2015 6:23:26 PM