.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

datalist image to gridview in asp.net

Posted By: neha     Posted Date: November 23, 2010    Points:2   Category :ASP.Net
hi friends,

How to select / Edit image datalist to gridview in asp.net

please correct this below code,

Display all images view in DataList.

If i click the Image in datalist ,

that image display in gridview and name is displayed in txtname.

Finally insert image & name in database.

Please go through the code and correct it and how to save gridview image to database .


This is my code,


<asp:DataList id="DataList1" runat="server" RepeatDirection="Horizontal" HorizontalAlign="Right" Font-Size="10pt" CssClass="listStyle" BorderWidth="4px" BorderColor="Black" BorderStyle="Solid" >

<asp:Image ID="img1" runat="server" Height="80" Width="80" ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "sid")) %>'
<asp:LinkButton runat="server" ID="lnkbtnEdit" CommandArgument='<%# Eval("imageID") %>'
CommandName="Edit" title="Edit" OnClick="lnkBtnEdit_Click"></asp:LinkButton>

<EditItemStyle BorderColor="#004040" />
<AlternatingItemStyle BackColor="White" BorderColor="White" />
<HeaderStyle BackColor="Silver" />

<asp:GridView ID="GridView1" runat="server" Style="position: relative">


<asp:TextBox ID="txtname" runat="server" Style="position: relative"></asp:TextBox>

<asp:Button ID="btnsubmit" runat="server" OnClick="btnsubmit_Click" Style="position: relative"
Text="Submit" />


SqlDataAdapter ada = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
public SqlConnection OpenConnection(SqlConnection c)
c.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];

if (c.State == ConnectionState.Closed)
return c;
public DataTable fetchAllImage()
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

string sql = "SELECT * from erlogo";

SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
return dt;

public string FormatURL(System.Object strArgument)
return ("homeimageread.aspx?sid=" + strArgument);

protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)

DataList1.DataSource = fetchAllImage();
protected void lnkBtnEdit_Click(object sender, System.EventArgs e)
string imageID = ((LinkButton)sender).CommandArgument;

protected void btnsubmit_Click(object sender, EventArgs e)



No response found. Be the first to respond this post
Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend