this is velsamy , i have created a aspx web form for retreiving and display the inserted records form the database, in GridView by using Datasource and bindind with
edit and delete Buttons. its all finely working . but the problem is while i am going to update the fields in gridview the null valus also updated. but i don't want to update the null values i have to protect the null values there itself. so
kindly give me solution as soon as possible.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
DeleteCommand="DELETE FROM [robot] WHERE [robot_id] = @original_robot_id AND (([robot_name] = @original_robot_name) OR ([robot_name] IS NULL AND @original_robot_name IS NULL))"
InsertCommand="INSERT INTO [robot] ([robot_name]) VALUES (@robot_name)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [robot]"
UpdateCommand="UPDATE [robot] SET [robot_name] = @robot_name WHERE [robot_id] = @original_robot_id AND (([robot_name] = @original_robot_name) OR ([robot_name] IS NULL AND @original_robot_name IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_robot_id" Type="Int32" />
<asp:Parameter Name="original_robot_name" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="robot_name" Type="String" />
<asp:Parameter Name="original_robot_id" Type="Int32" />
<asp:Parameter Name="original_robot_name" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="robot_name" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
velsamy
Member
13 Points
26 Posts
update the field values in gridview
Sep 12, 2012 11:24 AM|LINK
Hi all,
this is velsamy , i have created a aspx web form for retreiving and display the inserted records form the database, in GridView by using Datasource and bindind with edit and delete Buttons. its all finely working . but the problem is while i am going to update the fields in gridview the null valus also updated. but i don't want to update the null values i have to protect the null values there itself. so kindly give me solution as soon as possible.
Thanks and Regards,
Velsamy
santosh.jagd...
Star
7625 Points
1454 Posts
Re: update the field values in gridview
Sep 12, 2012 11:34 AM|LINK
hi velsamy, please check here
http://www.4guysfromrolla.com/articles/112807-1.aspx
MCP
ItsSunny
Contributor
2163 Points
676 Posts
Re: update the field values in gridview
Sep 12, 2012 11:35 AM|LINK
are you using edititemtemplate.Can you share your code
Arun Sunny.
velsamy
Member
13 Points
26 Posts
Re: update the field values in gridview
Sep 13, 2012 03:44 AM|LINK
Hi Sunny,
this is my code :
<asp:GridView ID="gridrobot" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" Font-Size="10pt"
DataKeyNames="robot_id" DataSourceID="SqlDataSource1">
<HeaderStyle BackColor="#336699" ForeColor="White" HorizontalAlign="Left" Height="25" BorderWidth="2" />
<Columns>
<asp:BoundField DataField="robot_id" HeaderText="robot_id"
InsertVisible="False" ReadOnly="True" SortExpression="robot_id" />
<asp:BoundField DataField="robot_name" HeaderText="robot_name"
SortExpression="robot_name" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="LinkButton3" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:Button>
<asp:Button ID="LinkButton4" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:Button>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
DeleteCommand="DELETE FROM [robot] WHERE [robot_id] = @original_robot_id AND (([robot_name] = @original_robot_name) OR ([robot_name] IS NULL AND @original_robot_name IS NULL))"
InsertCommand="INSERT INTO [robot] ([robot_name]) VALUES (@robot_name)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [robot]"
UpdateCommand="UPDATE [robot] SET [robot_name] = @robot_name WHERE [robot_id] = @original_robot_id AND (([robot_name] = @original_robot_name) OR ([robot_name] IS NULL AND @original_robot_name IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_robot_id" Type="Int32" />
<asp:Parameter Name="original_robot_name" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="robot_name" Type="String" />
<asp:Parameter Name="original_robot_id" Type="Int32" />
<asp:Parameter Name="original_robot_name" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="robot_name" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
velsamy
Member
13 Points
26 Posts
Re: update the field values in gridview
Sep 20, 2012 03:15 AM|LINK
hi ,
I shared the code will u please givr the solution for me,
also i set the fields as unique, so i have to give the alert while i update the duplicate values
velsamy
Member
13 Points
26 Posts
Re: update the field values in gridview
Sep 20, 2012 03:59 AM|LINK
Hi santhosh ,
I hope it will help me
thanx
Velsamy